What keyword is used to create a generator function?
Click to see answer
yield
Click to see question
What keyword is used to create a generator function?
yield
What is the smallest individual unit in a Python program?
Token.
What will the program print if the value of C is greater than or equal to 100?
The program will print 'Value is Equal to 100'.
What happens when an expression is evaluated?
When an expression is evaluated, a statement is executed, meaning some action takes place.
What are binary operators in Python?
Binary Operators are those operators that require two operands to operate upon.
What are literals in Python?
Literals/Constants are values that cannot be changed during the execution of the program.
What are non-graphic (escape) characters in Python?
They are special characters that cannot be typed directly from the keyboard, such as backspace, tabs, and enter, and are represented by escape characters starting with a backslash ().
What are Rvalues in Python?
Rvalues are expressions that come on the right-hand side of an assignment and refer to the values being assigned to a variable.
What is a block in Python?
A group of statements that are executed together, such as functions, conditions, or loops.
What does the print() function do in Python?
The print() function outputs values to the console, automatically inserting spaces between different values by default.
What does the special literal None represent in Python?
It indicates absence of value.
What is the purpose of the << operator in Python?
The << operator is used to shift bits to the left.
Provide an example of dynamic typing in Python.
Example: x = 100 # numeric type, then x = 'Central Public School' # now x points to string type.
What error will occur if you try to print a variable that hasn't been defined?
Python will show an error: 'x' not defined.
How do you check the type of a string variable in Python?
You can use type(). For example: >>> name = 'amar' >>> type(name) <class 'str'>
How do you assign multiple values to multiple variables in Python?
a, b, c = 11, 15, 25
What is a multiline string in Python?
A multiline string allows you to store text across multiple lines, using triple quotes or by using backslashes to indicate continuation.
What is the escape sequence for a new line in Python?
The escape sequence for a new line is '\n'.
What is a function in Python?
A block of code that has a name and can be reused by specifying its name in the program where needed.
What is the syntax for taking user input in Python?
The syntax is: variable_name = input('Message to Display')
What is Python?
Python is a high-level, general-purpose, and very popular programming language known for its readability and versatility. It was created by Guido van Rossum and released in 1991. Key features include readable syntax, interpreted language, dynamic typing, versatility, extensive libraries, and cross-platform support.
What is a statement in programming?
A statement is a programming instruction that performs an action, such as 'print("Welcome to Python")' or assigning a value to a variable like 'a=100'.
What are operators in Python?
Operators are symbols that perform specific operations when applied on variables.
What must every variable in Python have?
Every variable must have its own identity, type, and value.
List some arithmetic binary operators.
What types of literals does Python support?
Python supports String Literals, Numeric Literals (which include integer, float, and complex), Boolean Literals, Literal Collection, and Special Literals (like None).
Provide an example of using the print() function with a custom separator.
Example: print('Name is', 'amar', 'maurya', sep='&&') outputs 'Name is && amar && maurya'.
Provide an example of using the bitwise AND operator in Python.
print(12 & 7) results in 4.
What is the purpose of the is not operator?
The is not operator checks if two identities are not the same.
What does the < operator signify?
The < operator signifies less than.
What does Logical OR do in Python?
Logical OR returns True if at least one of the operands is true.
What type of value is returned by the input() function?
The value returned by the input() function is always of string type.
What does the keyword 'if' do in Python?
'if' is used to create a conditional statement.
What will len('abc') return?
It will return 3.
What program can be written to find the area of a circle?
Write a program to enter the radius of the circle and calculate its area.
What will len('Vicky’s') return?
It will return 7.
What is type conversion in Python?
Type conversion in Python is the process of converting a value of one data type to another data type. If done by the programmer, it is known as type conversion or type casting; if done automatically by the compiler, it is called implicit type conversion.
What is an example of a statement that changes the state of a program?
An example is 'b=b+20', which assigns a new value to the variable b.
Give an example of implicit type conversion.
For example, if x = 100 (int) and y = 12.5 (float), assigning y to x will automatically convert x to float: x = y results in x being <type 'float'>.
How is a complex number represented in Python?
A complex number is made up of two floating point values, one for the real part and one for the imaginary part.
What does the >> operator do?
The >> operator shifts bits to the right.
Can you name some unary operators?
What does the imaginary part of a complex number use to denote it in Python?
The letter 'j'.
What are some examples of bitwise operators in Python?
& (Bitwise AND), ^ (Bitwise XOR), | (Bitwise OR)
What is the purpose of Logical AND in Python?
Logical AND returns True if both operands are true.
What is a multiline comment in Python?
‘ ‘ ‘ This is Multiline Comment’ ’ ’
What are the types of Integer Literals in Python?
Integer Literals can be Decimal (e.g., 1234, -50, +100), Octal (starting with 0o, e.g., 0o10 is decimal 8), and Hexadecimal (starting with 0x, e.g., 0xF is decimal 15).
What is the purpose of the == operator?
The == operator checks for equality.
What does the != operator signify?
The != operator signifies not equal to.
What characters can follow the initial letter in a Python identifier?
Any digit from 0 to 9 can be part of the identifier, except for the initial letter.
Give examples of Fractional Form in Floating Point Literals.
Examples of Fractional Form in Floating Point Literals include 12.0, -15.86, and 0.5, and 10. (which represents 10.0).
Which keyword is used to import a module?
import
What are individual words and punctuation marks in programming called?
Tokens or lexical units or lexical elements.
What are the types of tokens in Python?
Keywords, Identifiers, Literals, Operators, Punctuators.
What is indentation in Python?
Extra space before writing any statement, generally four spaces together mark the next indent level.
What is an expression in Python?
An expression is any legal combination of symbols that represent a value, generally a combination of operators and operands.
What is an example of a binary operation in Python?
10 + 25
What are comments in Python?
Comments are additional information in a program that is ignored by the interpreter and not executed.
What functions does Python provide for explicit type conversion?
Python provides functions like int(), float(), str(), and bool() for explicit type conversion.
What does the escape character '\t' represent?
It represents a horizontal tab.
What is the corrected code to avoid the 'not defined' error when printing x?
x = 0; print(x) will avoid the error.
Can you give examples of String Literals?
Examples of String Literals include 'Python', '123456', 'Hello, How are you?', '$', '4', and '@@'.
How does Python treat single and multiple characters in String Literals?
In Python, both single character and multiple characters enclosed in quotes, such as 'AM', 'am', and '*' are treated as the same.
Provide an example of using print() with a variable.
age = 20; print('Your Age is:', age)
How can we take input from a user in Python?
We can take input using the built-in function input().
What is a keyword in Python?
A keyword is a reserved word in a computer language that has a specific meaning and is used to define the syntax or structure of the Python language.
How is a function created in Python?
It is created with the def keyword.
Can keywords be used as identifiers in Python?
No, keywords aren’t allowed to be used as identifiers.
What is the first character rule for Python identifiers?
The initial letter of the identifier should be any letter or underscore (_).
What is the function of the '*=' operator in Python?
The '*=' operator multiplies the variable by the right operand and assigns the result to the variable.
What is the purpose of the 'while' keyword in Python?
'while' is used to create a while loop.
What is the maximum length for a Python identifier?
Identifiers can be as long as you want them to be.
Which keyword is used to break out of a loop?
break
What is the purpose of the function SeeYou() in the provided Python program?
The function SeeYou() prints 'This is my Function Definition'.
What is dynamic typing in Python?
Dynamic typing means a variable pointing to a value of a certain type can be made to point to a value/object of a different type.
How can you change the separator in the print() function?
You can change the separator by using the 'sep' parameter in the print() function.
What are Lvalues in Python?
Lvalues are expressions that come on the left-hand side of an assignment and refer to the memory location where a value can be assigned.
What are unary operators?
Unary operators are those operators that require one operand to operate upon.
What does the bitwise AND operator do in Python?
The bitwise AND operator (&) performs a binary AND operation on two bits.
What does the is operator check in Python?
The is operator checks if two identities are the same.
What is a full line comment in Python?
#This is Full line comment
How do you write an inline comment in Python?
area = length * bredth #This is in-line comment
What does Rvalues refer to?
Rvalues refer to the values we assign to a variable, which can appear on the right-hand side of an assignment.
What does the assignment operator '=' do in Python?
The assignment operator '=' assigns the value on the right to the variable on the left.
How can you check the size of a string in Python?
You can check the size using the len() function. Example: len('abc') will show the size as 3.
How do you represent a Hexadecimal Literal in Python?
A Hexadecimal Literal in Python starts with 0x, for example, 0xF represents decimal 15.
What is the structure of an Exponent Part in a Floating Point Literal?
The Exponent Part consists of two parts: Mantissa and Exponent. For example, 10.5 can be represented as 0.105 x 10^2, where 0.105 is the mantissa and 02 is the exponent.
Can a Python identifier be the same as a keyword?
No, an identifier should not be used as a keyword.
What does the 'in' operator check in Python?
The 'in' operator checks if a variable exists within a sequence.
What keyword is used for debugging in Python?
assert
Which keyword is used to end the execution of a function?
return
What is the Python Character Set?
The Python Character Set is a set of valid characters that Python can recognize, including letters (A-Z, a-z), digits (0-9), special symbols (+, -, *, /, etc.), white spaces (blank space, enter, tab), and other characters (all ASCII and UNICODE).
What are delimiters also known as?
Punctuators or separators.
How are variables defined in Python?
Variables are defined by assigning a value of the desired type to them.
Can a variable declared as a numeric type in Python be changed to store a string type?
Yes, a variable declared as a numeric type can be further used to store a string type or another type.
What does the expression 'salary * 10 / 100' represent?
It is an expression that calculates 10% of the salary.
How do you access the real and imaginary parts of a complex number in Python?
Use x.real for the real part and x.imag for the imaginary part.
Can a value appear on the left-hand side of an assignment in Python?
No, values cannot come to the left of an assignment; the left-hand side must be a memory location.
What is the function of the > operator?
The > operator signifies greater than.
How does Python determine the size of a string?
Python determines the size of a string as the count of characters in the string.
Provide an example of a simple function in Python.
def drawline(): print(“-”*40) print(“It is Designed by Class 11”) drawline()
What will len('') return?
It will return 1.
How to calculate the area of a rectangle using user input?
Write a program to enter length and breadth and calculate the area of the rectangle.
What will len('Meera's Toy') return?
It will return 11.
How can feet be converted into inches in a program?
Write a program to enter distance in feet and convert it into inches.
What keyword is used to declare a non-local variable?
nonlocal
What keyword represents an expression that results in true?
True
What keyword is used to create an anonymous function?
lambda
What are the two Boolean literals in Python?
True and False.
What will be the output of the following code: x, x = 100, 200; y, y = x + 100, x + 200; print(x, y)?
The output will be 200, 300.
How can you determine the type of a variable in Python?
You can use the type() function. For example: >>> salary = 100 >>> type(salary) <class 'int'>
What is the default separator used by print()?
The default separator used by print() is a space (' ').
How do comments begin in Python?
Comments in Python begin with the '#' symbol.
What is a String Literal in Python?
A String Literal is a collection of characters enclosed in double or single quotes.
How does Python treat single line strings?
Single line strings created using single or double quotes must terminate on the same line and will result in a SyntaxError if not properly terminated.
What is the output of the following code: x, y, z = 10, 20, 30; z, y, x = x+1, z+10, y-10; print(z, y, x)?
Output will be: 11, 30, 10
What will be the output of the following code: x, y = 7, 9; y, z = x-2, x+10; print(x, y, z)?
Output will be: 7, 5, 17
What does <= indicate in Python?
The <= operator indicates less than or equal to.
What is the second way to store a multiline string in Python?
By typing text in triple quotation marks. Example: Name = '''Central Public School'''
What does the >= operator represent?
The >= operator represents greater than or equal to.
What does the operator '/=' accomplish in Python?
The operator '/=' assigns the quotient of the variable and the right operand back to the variable.
How can we convert the input from string to numeric type?
We can convert the input to numeric type using int() or float() function.
Do upper and lower case letters matter in Python identifiers?
Yes, upper and lower case letters have distinct characteristics in Python identifiers.
What is a Decimal Literal in Python?
A Decimal Literal in Python is an Integer Literal that contains at least one digit and does not include a decimal point, such as 1234, -50, or +100.
What special characters are allowed in Python identifiers?
Except for the underscore (_), an identifier cannot contain any special characters.
How to calculate the volume of a cylinder using user input?
Write a program to enter radius and height of a cylinder and calculate its volume.
What keyword is used to handle exceptions in Python?
finally
Which keyword is used to create a loop?
for
What keyword is used to handle errors?
try
Which keyword checks if a value is present in a tuple, list, etc.?
in
What keyword represents a null value?
None
What is implicit type conversion in Python?
Implicit type conversion in Python occurs when the compiler automatically converts one data type to another, such as when an integer is assigned to a float variable.
Give an example of an expression that produces a value when evaluated.
An example is A + 10.
When is a variable created in Python?
A variable is created in Python when you assign a value to it; it is not created in memory until some value is assigned.
What will be the output of type() when the variable salary is set to 20000.50?
<class 'float'>
What is the syntax for assigning the same value to multiple variables in Python?
a = b = c = 50
What are the three ways to enter comments in Python?
The three ways to enter comments are Full Line Comment, Inline Comment, and Multiline Comment.
How can you display output in Python?
You can use the print() function. For example: print('Welcome')
What is the syntax for the print() function in Python?
print(message_to_print[,sep='string',end='string'])
What does Lvalues refer to?
Lvalues refer to the object to which you can assign a value, specifically the memory location.
How many keywords are there in Python 3.7?
There are 33 keywords in Python programming language version 3.7.
How is an Octal Literal represented in Python?
An Octal Literal in Python starts with the symbol 0o, such as 0o10, which represents decimal 8.
What does the '-=' operator do in Python?
The '-=' operator subtracts the right operand from the variable and assigns the result to the variable.
Which keyword is used to create an alias in Python?
'as' is used to create an alias.
What is the program to calculate total and percentage of a student?
Write a program to enter Name and marks of 5 subjects, then calculate total and percentage.
Are 'Myself' and 'myself' considered the same identifier in Python?
No, case matters when it comes to identifier names; they are not the same.
Which keyword is used to declare a global variable?
global
What keyword is used to define a class?
class
Which keyword is used to test if two variables are equal?
is
What keyword is used in conditional statements, same as else-if?
elif
Which statement is used to handle errors in try-except blocks?
except
How can a float be converted to an int in Python?
A float can be converted to an int in Python using the int() function. For example, int(50.25) results in 50.
Provide an example of Lvalues and Rvalues in Python.
In the expression x = 100, 'x' is an Lvalue and '100' is an Rvalue.
Is the expression '100 = x' valid in Python?
No, the expression '100 = x' is invalid because a value cannot be assigned to the left-hand side.
How can you store a multiline string in Python using a backslash?
By adding a backslash at the end of a normal single or double quoted string. Example: Name = 'Central Public \ School'
What is the function of Logical NOT in Python?
Logical NOT inverts the truth value of the operand.
What defines a Floating Point Literal in Python?
Floating Point Literals, also known as real literals, are numbers having fractional parts and can be represented in Fractional Form (e.g., 12.0, -15.86) or Exponent Form (e.g., 0.105 x 10^2).
What is a program to take input of two numbers and print their sum?
Write a program that takes two numbers as input and prints their sum.
What will len('\ab') return?
It will return 3.
What is the purpose of the '//=' operator in Python?
The '//=' operator performs floor division of the variable by the right operand and assigns the result to the variable.
What is the program to convert temperature from Fahrenheit to Celsius?
Write a program to enter temperature in Fahrenheit and convert it into Celsius.
What keyword is used to create an alias name?
as
Which keyword skips the next iteration of a loop?
continue
What keyword is used to delete an object?
del
What keyword is used to create a while loop?
while
What is an identifier in Python?
An identifier is a name given to a Class, Function, or Variable in Python that helps distinguish one entity from others.
What is the purpose of the '+=' operator in Python?
The '+=' operator adds the right operand to the variable and assigns the result to the variable.
What keyword is used to break out of a loop in Python?
'break' is used to break out of a loop.
What does the '**=' operator do in Python?
The '**=' operator raises the variable to the power of the right operand and assigns the result to the variable.
How can you see a list of Python keywords?
You can see a list of Python keywords by entering >>> help('keywords') in the Python interpreter.
Give an example of an invalid Python identifier.
Examples of invalid identifiers include Grade-Pay, $Amar007, and Roll No.
What keyword is used to create a conditional statement?
if
Which keyword is used in exception handling?
with
What is the purpose of the 'not in' operator in Python?
The 'not in' operator checks if a variable does not exist within a sequence.
What logical operator represents an expression that results in not being true?
False
Which logical operator is used to negate a condition?
not
Which keyword is used when the user doesn’t want any code to execute?
pass
What keyword is used to import specific parts of a module?
from
What keyword is used to raise exceptions or errors?
raise
What keyword is used to define a function?
def
Which keyword is used in a conditional statement to provide an alternative?
else
Give an example of a valid Python identifier.
Examples of valid identifiers include GradePay, File_12_2018, and _ismarried.