๐Ÿ“˜ Lesson 2 examples: Python Syntax and Variables examples


1๏ธโƒฃ Creating Variables

name = "Sameer"
age = 25
salary = 35000
is_employee = True

print(name)
print(age)
print(salary)
print(is_employee)

Output

Sameer
25
35000
True

2๏ธโƒฃ Variables with Different Data Types

student_name = "Ayesha"
roll_no = 12
percentage = 88.5
passed = True

print(student_name)
print(roll_no)
print(percentage)
print(passed)

Output

Ayesha
12
88.5
True

3๏ธโƒฃ Python Is Case-Sensitive

name = "Saddam"
Name = "Chandini"

print(name)
print(Name)

Output

Saddam
Chandini

4๏ธโƒฃ Assigning Multiple Variables at Once

name, age, city = "Gousya", 22, "Hyderabad"

print(name)
print(age)
print(city)

Output

Gousya
22
Hyderabad

5๏ธโƒฃ Variable Reassignment

person = "Sameer"
print(person)

person = "Ayesha"
print(person)

Output

Sameer
Ayesha

6๏ธโƒฃ Using Variables in Sentences

name = "Chandini"
age = 24

print(name, "is", age, "years old")

Output

Chandini is 24 years old

7๏ธโƒฃ Simple Calculation Using Variables

salary = 30000
bonus = 5000
total_income = salary + bonus

print("Total Income:", total_income)

Output

Total Income: 35000

8๏ธโƒฃ Checking Variable Data Types

name = "Saddam"
age = 28
height = 5.7

print(type(name))
print(type(age))
print(type(height))

Output

<class 'str'>
<class 'int'>
<class 'float'>

9๏ธโƒฃ Taking Input and Storing in Variables

name = input("Enter name: ")
age = input("Enter age: ")

print("Name:", name)
print("Age:", age)

Sample Output

Enter name: Sameer
Enter age: 26
Name: Sameer
Age: 26

๐Ÿ”Ÿ Input with Type Conversion

name = input("Enter name: ")
age = int(input("Enter age: "))

print(name, "will be", age + 1, "next year")

Sample Output

Enter name: Ayesha
Enter age: 23
Ayesha will be 24 next year

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *