pythonCopy code
if condition:
# code to execute if condition is True
elif another_condition:
# code to execute if another_condition is True
else:
# code to execute if none of the above conditions are True
pythonCopy code
age = 25
if age < 13:
print("Child")
elif age < 18:
print("Teenager")
elif age < 60:
print("Adult")
else:
print("Senior")
Copy code
Adult
pythonCopy code
def month_name(month):
pythonCopy code
months = {
1: "January",
2: "February",
3: "March",
}
pythonCopy code
return months.get(month, "Invalid month")
pythonCopy code
greeting = "Hello, World!"
pythonCopy code
string1 = "apple"
string2 = "banana"
result = string1 == string2
print(result) # Outputs: False
pythonCopy code
stringA = "Python"
stringB = "python"
result = stringA.lower() == stringB.lower()
print(result) # Outputs: True
pythonCopy code
sentence = "The sun is shining."
substring = "sun"
result = substring in sentence
print(result) # Outputs: True
pythonCopy code
text = "Hello world!"
extracted_word = text[6:11]
print(extracted_word) # Outputs: world
pythonCopy code
string1 = "Python"
string2 = "Rocks!"
concatenated_string = string1 + " " + string2
print(concatenated_string) # Outputs: Python Rocks!
pythonCopy code
word = "echo"
repeated_word = (word + "-") * 2 + word
print(repeated_word) # Outputs: echo-echo-echo