Why to Use Python?
Python can be used for :
1. Programming (for Placements/online contests/DSA)
2. Development (using a backend framework called Django)
3. Machine Learning / Data Science / Artificial Intelligence
Websites built using Python include Google, Youtube, Instagram, Netflix, Uber &
much more.
What to Install?
1. Python (https://www.python.org/)
2. PyScripter (https://rb.gy/bvnn69 )
3. PyCharm (https://www.jetbrains.com/pycharm/)
Our First Python Program
print("Hello World")
A Key Point to know about Python
It is a case sensitive language
Variables
Basic Types in Python - numbers(integers, floating), boolean, strings
Example 1 :
name = "shradha"
age = 22
print(name)
print(age)
Example 2 :
name = "shradha"
age = 22
name = "aman"
age = 24
print(name)
print(age)
Example 3 :
first_name = "shradha"
last_name = "khapra"
age = 19
is_adult = True
print(first_name + " " + last_name)
print(age)
print(is_adult)
, > Exercise Solution
first_name = "Tony"
last_name = "Stark"
age = 52
is_genius = True
Taking Input
name = input("What is your name? ")
print("Hello " + name)
print("Welcome to our cool Python class")
> Exercise Solution
superhero = input("What is your superhero name? ")
print(superhero)
Type Conversion
old_age = input("Enter your age : ")
#new_age = old_age + 2
#print(new_age)
new_age = int(old_age) + 2
print(new_age)
#Useful converion functions
# 1. float()
# 2. bool()
# 3. str()
# 4. int()
> Code for Sum of 2 Numbers
first_number = input("Enter 1st number : ")
second_number = input("Enter 2nd number : ")
sum = float(first_number) + float(second_number)
print("the sum is : " + str(sum))
Strings
name = "Tony Stark"
print(name.upper())
print(name)
print(name.lower())
print(name)
print(name.find('y'))
print(name.find('Y'))
print(name.find("Stark"))
print(name.find("stark"))
print(name.replace("Tony Stark", "Ironman"))
print(name)