Python_S2AIDS_2nd_Class
Python_S2AIDS_2nd_Class
1. Concatenation
2. Appending
3. Multiplication
1. Concatenation:
Two strings can be concatenated by using + operator.
'String Concatenation'
2. Appending:
A character can be appended to string using += operator or by reassignment.
str3 = 'Let'
ch = 's'
str3 += ch # str3 = str3 + ch
str3
'Lets'
3. String Multiplication:
String multiplication results a string with repitition. It can be done using * operator.
Good Afternoon
greeting='Good'
time='Afternoon'
gt=greeting+' '+time
print(gt)
Good Afternoon
The flow is controlled the values of few variables that decide the proceedings of a program.
The conditions statements have same basic structure in all programming languages. The list of
Control statements are:
1. if statement
2. if - else statements
3. if - elif - else statements
4. Nested if - else statements
5. Inline if - else statements
1. if statement:
Executes the statements inside the block only if the condition is satisfied.
Syntax:
if condition:
Statements
Python uses indentation (whitespace) to define the scope and grouping of code blocks
age = 18
x=100
y=200
if(x<y):
print("The condition is True")
2. if - else statements:
Executes else when if condition fails
Syntax:
if condition1:
Statements
else:
Statements
No
i = 44
if (i < 50):
print("i is smaller than 50")
print("i'm in if Block")
else:
print("i is greater than 15")
print("i'm in else Block")
print("i'm not in if and not in else Block")
i is smaller than 50
i'm in if Block
i'm not in if and not in else Block
The if...else statement is used to execute a block of code among two alternatives.
Syntax:
if condition1:
Statements
elif condition2:
Statements
else:
Statements
It's freezing!
if condition1:
if condition2:
Statements
else:
Statements
else:
if condition3:
Statements
else:
Statements
if condition1:
# Code to execute if condition1 is True
if condition2:
# Code to execute if condition1 and condition2 are True
else:
# Code to execute if condition1 is True but condition2 is
False
else:
# Code to execute if condition1 is False
if condition3:
# Code to execute if condition1 is False and condition3 is
True
else:
# Code to execute if condition1 and condition3 are False
x = 10
y = 20
if x > 5:
print("x is greater than 5")
if y > 15:
print("y is greater than 15")
else:
print("y is not greater than 15")
else:
print("x is not greater than 5")
if y > 15:
print("y is greater than 15")
else:
print("y is not greater than 15")
x is greater than 5
y is greater than 15
a=11
"even" if a%2==0 else "odd"
'odd'
a=-49
aa="positive" if a>0 else "negative"
print(aa)
negative
a = 2
b = 330
print("A") if a > b else print("B")