About Me

Welcome to the blog of Positive Mind
About Me | Learn Inredible
Motivational Tip & Tricks Tech Articles Printable Games VECTOR PRINTABLE Coreldraw Tutorial visiting card vector Wedding Cards Vector

LEARN PYTHON BASICS IN BEST LEARNING WAY

LEARN PYTHON BASICS IN BEST LEARNING WAY 

code

Learn Python learning basics and Get Ready for a basic self-knowledge in Data Science, Machine Learning and AI. Let’s Learn Python basic Concepts

Python is full of Modules             -             

codes & functions           -             

 

to print any function

print(“hello World”)      #it is just to comment purpose (no use of it only for reference)

‘’’this is a

multiline comment’’’

hellow world

 

variable1 = 4

print(variable1)

4

 

variable1 = 4

variable2=”this is variable 2”

print(variable1,variable2)

4 this is variable 2

 

Data types

Numbers, strings, lists, tuples, Dictionaries

 

7 operators

 

7 OPERATORS

 

+

addition

 print(2+3)

 

-

substraction

print (2-3)

 

*

multipilcation

print(2*3)

 

/

float division

print(4/2)

 

 

 

print(2/4)

 

//

integer division

print(5//2)

It removes 2.5 = 2

%

modulo, it gives reminder

print(6%2)

 

**

exponent

print(2**3)

 

 

 

 

 

 

 

Print

output

PRINT(“Lets Print 3+2, 3+2”)       

PRINT(“Lets Print 3+2, 3-2”)

PRINT(“Lets Print 3+2, 3*2”)

PRINT(“Lets Print 3+2, 3/2”)

PRINT(“Lets Print 3+2, 3%2”)

PRINT(“Lets Print 3+2, 3**2”)

PRINT(“Lets Print 3+2, 3//2”)

Lets Print 3+2 5

Lets Print 3+2 1

Lets Print 3+2 6

Lets Print 3+2 1.5

Lets Print 3+2 1

Lets Print 3+2 9

Lets Print 3+2 1

 

 

 

 

 

 

 

 

 

 

To add STRINGS

 

OUTPUT

SPACE

strings1 = “this is string 1”)

strings2 = “this is string 2”)

print(strings1+ strings2)

this is string 1this is string 2

strings are connected

print(strings1+ “ “ + strings2)

this is string 1 this is string 2

here both have a single space

 

 

to add    “   &   space

 

output

space

strings1 = “this is string 1 \””)

strings2 = “this is string 2”)

print(strings1+ “ “ + strings2)

this is string 1 “ this is string 2

to print  “

 

 

to add strings

 

output

space

strings1 = “this is string 1 \””)

strings2 = “this is string 2 ”)

print(strings1+ strings2+ end=“ ”)

print(“ another”)

this is string 1 “ this is string 2 another

to add print  in last word

a space behind “ can also give a space

 

to add at end of string

 

output

space

strings1 = (“this is string 1 ”)

strings2 = (“this is string 2”)

print(strings1+ strings2+ “ “ +,end=“ ”)

print(“ another”)

this is string 1 this is string 2 another

to add print  in last word

 

Formula

 

output

\n

Print(“line a\n line b)

# It defines to print on next line

Line a

Line b

\n

Print(“line a \n” *2 )

# it multiplys in to 2 lines

Line a

Line a

 

Line b

\t

strings1 = (“line A”)

strings2 = (“line B”)

Print=(string1\tstring2)

# \t means tab spacing

 

 

 

string1     string2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

LISTS

 

 

Output

Showing the position of words in list

space

LIST1=[1,2,3,4,”STRING”]

PRINT(LIST1[0])

PRINT(LIST1[1])

PRINT(LIST1[2])

PRINT(LIST1[3])

PRINT(LIST1[4])

 

LIST[4]=”THIS”

PRINT(LIST1[4])

 

1

2

3

4

STRING

 

 

THIS

 

 

 

 

 

If we change the list to new word it will assign that word as value

PRINT(LIST1[1:3]

[2,3]

 

LIST2=[23,45,”TWENTY”,LIST1]

PRINT(LIST1)

 

LIST1=[1,2,3,4,”STRING”]

PRINT LIST INSIDE LIST

 

 

 

 

LIST1.append(“last”)

Print(LIST1)

LIST1=[1,2,3,4,”STRING”,”last”]

 

Insert end

LIST1.insert(2, “last”)

Print(LIST1)

LIST1=[1,2, ”last”,3,4,”STRING”]

 

Insert on our position

 

LIST1=[1,20,30,4]

Print(LIST1)

 

 

LIST1.sort ()

Print(LIST1)

 

LIST1=[1,4,20,30]

Arranging in order

LIST1.sort ()

LIST1.reverse ()

Print(LIST1)

 

 

LIST1=[30,20,4,1]

Arranging in reverse order

del list1[3]

LIST1=[30,20,1]

DELETS VALUE AS PER POSITION

 

TUPLES

 

()

#we cant change tuples

 

tuple1=(1,6,5,4)

Print(len(tuple))

 

 

4

 

Calculates length of tuple

tuple1=list(tuple)

Print(tuple1)

 

 

tuple=[1,6,5,4]

 

We can convert tuple to list

Tuple1=(1,6,5,4)

tuple1=list(tuple)

Print(max(tuple))

 

 

 

6

 

We can find Maximum numbers

Tuple1=(1,6,5,4)

tuple1=list(tuple)

Print(min(tuple))

 

 

 

1

 

We can find Minimum numbers

 

 

 

DICTIONARIES

WORD

MEANING

 

dict1={ “east”:”100”,

              “west”:”500”,

“nort”:”600”,

“south”:”700”}

print(dict1(‘east’))

 

 

 

 

 

100

 

dict1[east]=”800”

print(dict1(‘east’))

 

800

#we can change dict value

print(dict1.get(‘south’))

100

 

print(dict1.key())

dict keys(‘ease’, ‘west’, ‘north’, ‘west’)

it prints key

print(dict1.values())

dict keys([‘100’, ‘500’, ‘600’, ‘700’])

it prints values

 

 

if             elif         else       …………………..SHORTCUTS

 

output

a=4

 

if a==4:

   print(“a is 4”)

elif a==3              

    print(“a is 3”)

else:

    print(“a is neither 3 nor 4”)

 

 

 

 

 

 

 

 

a is 4

a=13

 

if a==4:

   print(“a is 4”)

elif a==3              

    print(“a is 3”)

else:

    print(“a is neither 3 nor 4”)

 

 

 

 

 

 

 

 

a is neither 3 nor 4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

loops     …………………..SHORTCUTS

 

output

 

for i in range(0,10):

   print(i)

 

0

1

2

3

4

5

6

7

8

9

 

It prints list

In range

List1=[1,8,3,9,5]

for i in range(0,10):

   print(i)

 

1

8

3

9

5

 

If list1 assigned it prints list in range

 

While loop

i=0

while i is not 10

     print(i)

0

0

0

0

0

0

it will print unlimited times

because we have not said where to stop

i=0

while i is not 10

     print(i)

     i=i+1

0

1

2

3

4

5

6

7

8

9

This will stop our loop till it prints 10 counts

 

It is like operators

Is   =

not

i=0

while i is not 10:

         i=i+1

 if i is 3:

          break

     print(i)

 

 

 

 

0

1

2

 

 

if i is 3:

          break

it breaks loops when we stop it

 

i=0

while i is not 10:

         i=i+1

 if i is 3:

          continue

     print(i)

 

 

1

2

4

5

6

7

8

9

 

 

It delets the value 3 assigned in the loop listed

 

 

 

 

 

#functions

If we need to regularly

Or need to run function inside function

 

 

OUTPUT

 

Def function1(num1+num2):

    Return(num1+num2)/2

 

a = function1(2,3)

print(a)

 

 

 

2.5

 

We created a function

 

#file handling

 

Create a file naming chirag.txt

from file

 

 

file1=open("chirag.txt,"w")

w=write

file1=open("chirag.txt,"r")

print(file1.read())

 

 

 

print(file.mode)

It shows which mode we are running the file

chirag.txt

 

 

print(file.name)

It can print file name

 

file.close()

 

 

 

Import os

 

os.remove(“chirag.txt”)

 

 

object oriented programming

 

design concepts

 

class

output

def h1(self):

      print("you are inside h1)

      return 0

      variable1=4

 

obj = chiragcodes()

print(obj.h1())

 

 

 

 

 

you are inside h1

0

 


Advertise

Your AD Here

Subscribe

Enter your e-mail below and get notified on the latest blog posts.

Popular Posts


Follow Me


SUBSCRIBE

Join my mailing list to receive updates on the latest blog posts and other things.