Python Basics
Python Basics
Python Basics
PYTHON BASICS
1.INTRODUCTION
2.PYTHON DRAWBACK
3.PYTHON BLOCK STRUCTURE
4.DYNAMIC NATURE
5.OPERATORS
6.STRINGS
7.LIST
8.REFERENCES
INTRODUCTION
Why python ?
Python is a powerful programming language.
Python is a dynamic typed programming language.
Python is user friendly syntax
In python we have supporting libraries.
We can use python in GUI,Web
development,scripting,Image processing,Machine
learning .
Contd..
Who uses python ?
Google ,youtube,dropbox storage service,
Raspberry pi embedded board systems,
Intel,Cisco,HP,IBM
PYTHON DRAWBACK
invalid:
age_*
+age
variable names are case sensitive
age is not equal to Age
variable name should not be a python keyword
ex:- pass , break , continue
Contd..
Dynamic nature :
statically typed programming languages are
c,c++,java
a=10
objects
b=a
System table Type = integer
a Value = 10
Count =2
others
1024
Contd..
Dynamic nature :
statically typed programming languages are
c,c++,java
a=10
objects
b=a
System table Type = integer
a Value = 10
Count =2
others
1024
Contd..
Object are garbage collected
i=10
i=hello
i=5.9
ID function :-
id function return object identity
Printing the id
a=10
print(id(a)) // the value is 1024
Identity operator
To check the two objects share same memory location we use identity operator.
In python 2 types of identity operators are there:
1.is operator
2.is not operator
syntax: obj1 is obj2
x=10 , y=10
if x is y :
print(“same”)
else :
print(“different”)
Contd..
2. is not operator
syntax :obj1 is not obj2
x=10
y=20
if x is not y :
print(“different”)
else:
print(“same”)
Printing value of a variables and string formatting
name = “python”
year = 2021
print(“name:”,name, “year :”,year)
print(“Name:”+name+”year:”+year)
above statement will be type error
In python we cannot concatenate string and integer then we go for typecast
now use the type cast
print(“Name :” +name+ “year: ” +str(year)”)
use string format
name = “python”
year = 2021
print(“name:{ } year:{ } ”.format(name,year))
STRINGS
0 1 2 3 4 5
P Y T H O N
-5 -4 -3 -1 Reverse indexing
-6 -2
Str = “python”
Str[2] = ‘z’
String is immutable
Values can’t be changed
SLICING STRING IN PYTHON
Str = “python”
Print (str[0:3])
print(str[-4:-1])
Forward index
0 1 2 3 4 5
P y t h o n
-6 -5 -4 -3 -2 -1
Reverse index
List[0:index]
List[index:length of the string]
Str = “python”
print(str[:3]) // str[0:3]
print(str[3:]) // str[3:6]
String methods
Length of a string :
str = “python”
print(len(str))
str = “ python ”
print(str.strip())