Professional Documents
Culture Documents
Python From Scratch
Python From Scratch
Python
• Python is interpreted.
• Can be treated in a Procedural , object oriented or functional way.
• Python follows indentation.
• Python Variables
• IDE
• Spyder, Pycharm etc or use command line.
• Comments
• Use # to comment any line in python
• Variables are created when we assign a value to it.
• Example : x=5
• To print Hello World in Python
• Print (“Hello World”)
Python
• To specify data type of a variable casting can be done
• X=str(3)
• Y=int(3)
• To check the data type of a variable use type
• Print(type(x))
• Variables are case sensitive
• String variables can be defined in single or double quotes both
• Example : x=“string” or x=‘string’
Random Number Generation
Import random
X=random.randrange(1,10)
Print (x)
String
• Immutable objects- cannot be changed
• a=“Hello , World!” #string
• a=“””multi line string
declaration””” H E L L O , W O R L D !
• String are arrays 0 1 2 3 4 5 6 7 8 9 10 11
• Print (a[1]) # H
-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
• str.maketrans(x,y,[z])
• x- what to replace ,y- what should be replace ,z – remove that from string
• Returns a dictionary
• str.translate(Dictionary or maketrans output)
List
• List are mutable ,allows duplicate and changeable
• L=[“apple”,”banana”,”orange”]
• To find the length of the list – len(l)
• To access the item of list –l[0], l[1]…..
• L.insert(position,item)
• L.append(item)
• L.extend(iterable)
• L.remove(item)
• L.pop([index]) # by default last item is removed
• Del l[index]
• Del l
• L.clear()