Python Learning
Python Learning
x=”john”
Y=”collage”
Print( x, y, sep=’\n’)//out put john
Collage
Print( x, y, sep=’\t’)//out put john collage
condition
IF ELSE
X=33
Y=33 OUT PUT
If a>b:
Print(“a is greater than”)
Else:
Print(“b is greater than”)
IF ELIF ELSE
1
Output
x = 10
Y=4
x is greater than Y
if x > Y:
print("x is greater than Y")
Elif x == 10:
print("x is equal to Y")
else:
print("x is less than Y ")
2.
temperature = 15 Output
It's mild. Is nice day
if temperature > 30:
print("It's hot!")
Elif temperature < 15:
print("It's cold!")
else:
print("It's mild. Is nice day")
3.
age = 20
Output
if age >= 18: Allowed to vote
print("Allowed to vote.")
else:
print("Not allowed to vote.")
4.
m = 85
if m >= 90:
grade = 'A'
elif m >= 80: Output
grade = 'B' Grade: B
elif m >= 70:
grade = 'C'
elif m >= 60:
grade = 'D'
else:
grade = 'F'
print("Grade:", grade)
# This is a comment
print("Hello, World!") # Output: Hello, World!
# Variables
x = 10
y = 5.5
name = "Alice"
# Data Structures
numbers = [1, 2, 3, 4, 5] # List
person = {"name": "Alice", "age": 30} # Dictionary
# Conditional Statements
if x > y:
print("x is greater than y")
else:
print("y is greater than or equal to x")
# Loops
for number in numbers:
print(number)
# Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))