Python Basics
Python Basics
• Python:
1. Interpreted
2. High level language
3. Object Oriented
Extensions:
1. (.ipynb)
2. (.py)
CONTD..
• DATA TYPES:
• #variables names can
1. Numeric
only have alphabet,
2. String/Object -- sequence of characters numbers and underscore.
3. Boolean (True/False) • #variables names can
only start with alphabet
4. DateTime and underscore.
• VARIABLES: • #variables can not start
#defining my first variable with any number.
• #variables names are
my_first_variable = 10 case sensitive.
#defining my second variable
my_second_variable = 'this is my second variable'
Contd..
bool1 = True from datetime import date
bool2 = False today_date = date(2023,7,31)
type(bool1) bool today_date datetime.date(2023, 7, 31)
Operators : (+, -, *, /, //, =, ==, %)
• Concatenation:
str1 = 'day 1' • 4/2 2.0
str2 = 'Python'
• floor division 5 // 2 2
conc = str1 +' '+ str2 • 5 % 2 (remainder) 1
Defining a function: • #exponential (2 ** 3)
#2 raised to the power 3
def sum(var1, var2): 2 ** 3 8
return var1 + var2
Assignment Operators..
a += 3 a=a+3
b-=1 b = b-1
a /= 2 a = a/2
a == b a is equal to b
a != b a is not equal to b
dict_items([('India', 'New
dict1.items() Delhi'), ('Australia',
'Canberra'), ('United States',
'Washington DC'), ('England',
'London')])
Dictionary
for key,value in dict1.items():
print(f'The capital of {key} is {value}')