Mid Questions With Answers
Mid Questions With Answers
The if statement
The if statement is used to test a particular
condition and if the condition is true, it executes a
block of code known as if-block. The condition of if
statement can be any valid logical expression which
can be either evaluated to true or false.
Syntax:
1.if expression:
2. statement
Ex: Program to print the given number is even or
odd
Example
x = 41
if x > 10:
print("Above ten,")
if x > 20:
print("and also above 20!")
else:
print("but not above 20.")
Ex:
Ex:
Str=”ramarao”
Print(str[1])
Syntax: string.capitalize()
Ex:
txt=”hello world”
x=txt.capitalize()
print(x)
2.Casefold()
Syntax: String.casefold()
Ex:
txt=”Hello world”
x=txt.casefold()
print(x)
3.Count()
Ex:
4.Upper()
Syntax: String.upper(“string_name”)
Ex:
5.Lower()
It returns a copy of a letter or a word
convert to lower case
Syntax:String.lower(“string_name”)
Ex:
i=1
while i < 6:
print(i)
break
i=i+1
Continue: It is used to skip all the
remaining statements in the current iteration of the
loop
and moves the control back to the
top of the loop
Ex:
i=1
while i < 6:
print(i)
continue
i=i+1
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Dictionary Items
Example
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict["brand"])
Ordered or Unordered
Changeable
Example