Computer Science (Python)

Created by Sam Kshitij

p.4

What keyword is used to create a generator function?

Click to see answer

p.4

yield

Click to see question

1 / 182
p.4
Keywords in Python

What keyword is used to create a generator function?

yield

p.2
Tokens in Python

What is the smallest individual unit in a Python program?

Token.

p.17
Basic Input and Output

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'.

p.18
Functions and Blocks in Python

What happens when an expression is evaluated?

When an expression is evaluated, a statement is executed, meaning some action takes place.

p.14
Operators in Python

What are binary operators in Python?

Binary Operators are those operators that require two operands to operate upon.

p.6
Literals in Python

What are literals in Python?

Literals/Constants are values that cannot be changed during the execution of the program.

p.7
Literals in Python

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 ().

p.21
Identifiers in Python

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.

p.20
Functions and Blocks in Python

What is a block in Python?

A group of statements that are executed together, such as functions, conditions, or loops.

p.26
Basic Input and Output

What does the print() function do in Python?

The print() function outputs values to the console, automatically inserting spaces between different values by default.

p.10
Literals in Python

What does the special literal None represent in Python?

It indicates absence of value.

p.15
Operators in Python

What is the purpose of the << operator in Python?

The << operator is used to shift bits to the left.

p.24
Dynamic Typing and Variable Types

Provide an example of dynamic typing in Python.

Example: x = 100 # numeric type, then x = 'Central Public School' # now x points to string type.

p.23
Identifiers in Python

What error will occur if you try to print a variable that hasn't been defined?

Python will show an error: 'x' not defined.

p.25
Dynamic Typing and Variable Types

How do you check the type of a string variable in Python?

You can use type(). For example: >>> name = 'amar' >>> type(name) <class 'str'>

p.22
Multiple Assignment

How do you assign multiple values to multiple variables in Python?

a, b, c = 11, 15, 25

p.7
Literals in Python

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.

p.7
Literals in Python

What is the escape sequence for a new line in Python?

The escape sequence for a new line is '\n'.

p.19
Functions and Blocks in Python

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.

p.12
Basic Input and Output

What is the syntax for taking user input in Python?

The syntax is: variable_name = input('Message to Display')

p.1
Introduction to Python

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.

p.18
Functions and Blocks in Python

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'.

p.13
Operators in Python

What are operators in Python?

Operators are symbols that perform specific operations when applied on variables.

p.20
Dynamic Typing and Variable Types

What must every variable in Python have?

Every variable must have its own identity, type, and value.

p.14
Operators in Python

List some arithmetic binary operators.

  • (Addition), - (Subtraction), * (Multiplication), / (Division), % (Remainder), ** (Exponent), // (Floor Division)
p.6
Literals in Python

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).

p.26
Basic Input and Output

Provide an example of using the print() function with a custom separator.

Example: print('Name is', 'amar', 'maurya', sep='&&') outputs 'Name is && amar && maurya'.

p.14
Operators in Python

Provide an example of using the bitwise AND operator in Python.

print(12 & 7) results in 4.

p.15
Operators in Python

What is the purpose of the is not operator?

The is not operator checks if two identities are not the same.

p.15
Operators in Python

What does the < operator signify?

The < operator signifies less than.

p.16
Operators in Python

What does Logical OR do in Python?

Logical OR returns True if at least one of the operands is true.

p.12
Basic Input and Output

What type of value is returned by the input() function?

The value returned by the input() function is always of string type.

p.3
Keywords in Python

What does the keyword 'if' do in Python?

'if' is used to create a conditional statement.

p.8
Literals in Python

What will len('abc') return?

It will return 3.

p.12
Basic Input and Output

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.

p.8
Literals in Python

What will len('Vicky’s') return?

It will return 7.

p.11
Dynamic Typing and Variable Types

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.

p.18
Functions and Blocks in Python

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.

p.11
Dynamic Typing and Variable Types

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'>.

p.10
Literals in Python

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.

p.15
Operators in Python

What does the >> operator do?

The >> operator shifts bits to the right.

p.13
Operators in Python

Can you name some unary operators?

  • (Unary Plus), - (Unary Minus), ~ (Bitwise Complement), Not (Logical Negation)
p.10
Literals in Python

What does the imaginary part of a complex number use to denote it in Python?

The letter 'j'.

p.14
Operators in Python

What are some examples of bitwise operators in Python?

& (Bitwise AND), ^ (Bitwise XOR), | (Bitwise OR)

p.16
Operators in Python

What is the purpose of Logical AND in Python?

Logical AND returns True if both operands are true.

p.19
Comments in Python

What is a multiline comment in Python?

‘ ‘ ‘ This is Multiline Comment’ ’ ’

p.9
Literals in Python

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).

p.15
Operators in Python

What is the purpose of the == operator?

The == operator checks for equality.

p.15
Operators in Python

What does the != operator signify?

The != operator signifies not equal to.

p.5
Identifiers in Python

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.

p.9
Literals in Python

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).

p.4
Keywords in Python

Which keyword is used to import a module?

import

p.2
Tokens in Python

What are individual words and punctuation marks in programming called?

Tokens or lexical units or lexical elements.

p.2
Tokens in Python

What are the types of tokens in Python?

Keywords, Identifiers, Literals, Operators, Punctuators.

p.20
Functions and Blocks in Python

What is indentation in Python?

Extra space before writing any statement, generally four spaces together mark the next indent level.

p.17
Operators in Python

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.

p.13
Operators in Python

What is an example of a binary operation in Python?

10 + 25

p.18
Basic Input and Output

What are comments in Python?

Comments are additional information in a program that is ignored by the interpreter and not executed.

p.11
Dynamic Typing and Variable Types

What functions does Python provide for explicit type conversion?

Python provides functions like int(), float(), str(), and bool() for explicit type conversion.

p.7
Literals in Python

What does the escape character '\t' represent?

It represents a horizontal tab.

p.23
Identifiers in Python

What is the corrected code to avoid the 'not defined' error when printing x?

x = 0; print(x) will avoid the error.

p.6
Literals in Python

Can you give examples of String Literals?

Examples of String Literals include 'Python', '123456', 'Hello, How are you?', '$', '4', and '@@'.

p.6
Literals in Python

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.

p.25
Basic Input and Output

Provide an example of using print() with a variable.

age = 20; print('Your Age is:', age)

p.12
Basic Input and Output

How can we take input from a user in Python?

We can take input using the built-in function input().

p.3
Keywords in Python

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.

p.19
Functions and Blocks in Python

How is a function created in Python?

It is created with the def keyword.

p.3
Keywords in Python

Can keywords be used as identifiers in Python?

No, keywords aren’t allowed to be used as identifiers.

p.5
Identifiers in Python

What is the first character rule for Python identifiers?

The initial letter of the identifier should be any letter or underscore (_).

p.16
Operators in Python

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.

p.3
Keywords in Python

What is the purpose of the 'while' keyword in Python?

'while' is used to create a while loop.

p.5
Identifiers in Python

What is the maximum length for a Python identifier?

Identifiers can be as long as you want them to be.

p.4
Keywords in Python

Which keyword is used to break out of a loop?

break

p.17
Functions and Blocks in Python

What is the purpose of the function SeeYou() in the provided Python program?

The function SeeYou() prints 'This is my Function Definition'.

p.24
Dynamic Typing and Variable Types

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.

p.26
Basic Input and Output

How can you change the separator in the print() function?

You can change the separator by using the 'sep' parameter in the print() function.

p.21
Identifiers in Python

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.

p.13
Operators in Python

What are unary operators?

Unary operators are those operators that require one operand to operate upon.

p.14
Operators in Python

What does the bitwise AND operator do in Python?

The bitwise AND operator (&) performs a binary AND operation on two bits.

p.15
Operators in Python

What does the is operator check in Python?

The is operator checks if two identities are the same.

p.19
Comments in Python

What is a full line comment in Python?

#This is Full line comment

p.19
Comments in Python

How do you write an inline comment in Python?

area = length * bredth #This is in-line comment

p.21
Identifiers in Python

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.

p.16
Operators in Python

What does the assignment operator '=' do in Python?

The assignment operator '=' assigns the value on the right to the variable on the left.

p.8
Literals in Python

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.

p.9
Literals in Python

How do you represent a Hexadecimal Literal in Python?

A Hexadecimal Literal in Python starts with 0x, for example, 0xF represents decimal 15.

p.9
Literals in Python

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.

p.5
Identifiers in Python

Can a Python identifier be the same as a keyword?

No, an identifier should not be used as a keyword.

p.16
Operators in Python

What does the 'in' operator check in Python?

The 'in' operator checks if a variable exists within a sequence.

p.4
Keywords in Python

What keyword is used for debugging in Python?

assert

p.4
Keywords in Python

Which keyword is used to end the execution of a function?

return

p.1
Python Character Set

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).

p.2
Tokens in Python

What are delimiters also known as?

Punctuators or separators.

p.20
Dynamic Typing and Variable Types

How are variables defined in Python?

Variables are defined by assigning a value of the desired type to them.

p.24
Dynamic Typing and Variable Types

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.

p.17
Operators in Python

What does the expression 'salary * 10 / 100' represent?

It is an expression that calculates 10% of the salary.

p.10
Literals in Python

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.

p.21
Identifiers in Python

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.

p.15
Operators in Python

What is the function of the > operator?

The > operator signifies greater than.

p.8
Literals in Python

How does Python determine the size of a string?

Python determines the size of a string as the count of characters in the string.

p.19
Functions and Blocks in Python

Provide an example of a simple function in Python.

def drawline(): print(“-”*40) print(“It is Designed by Class 11”) drawline()

p.8
Literals in Python

What will len('') return?

It will return 1.

p.12
Basic Input and Output

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.

p.8
Literals in Python

What will len('Meera's Toy') return?

It will return 11.

p.12
Basic Input and Output

How can feet be converted into inches in a program?

Write a program to enter distance in feet and convert it into inches.

p.4
Keywords in Python

What keyword is used to declare a non-local variable?

nonlocal

p.4
Keywords in Python

What keyword represents an expression that results in true?

True

p.4
Keywords in Python

What keyword is used to create an anonymous function?

lambda

p.10
Literals in Python

What are the two Boolean literals in Python?

True and False.

p.23
Dynamic Typing and Variable Types

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.

p.25
Dynamic Typing and Variable Types

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'>

p.26
Basic Input and Output

What is the default separator used by print()?

The default separator used by print() is a space (' ').

p.18
Basic Input and Output

How do comments begin in Python?

Comments in Python begin with the '#' symbol.

p.6
Literals in Python

What is a String Literal in Python?

A String Literal is a collection of characters enclosed in double or single quotes.

p.7
Literals in Python

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.

p.22
Multiple Assignment

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

p.22
Multiple Assignment

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

p.15
Operators in Python

What does <= indicate in Python?

The <= operator indicates less than or equal to.

p.8
Literals in Python

What is the second way to store a multiline string in Python?

By typing text in triple quotation marks. Example: Name = '''Central Public School'''

p.15
Operators in Python

What does the >= operator represent?

The >= operator represents greater than or equal to.

p.16
Operators in Python

What does the operator '/=' accomplish in Python?

The operator '/=' assigns the quotient of the variable and the right operand back to the variable.

p.12
Basic Input and Output

How can we convert the input from string to numeric type?

We can convert the input to numeric type using int() or float() function.

p.5
Identifiers in Python

Do upper and lower case letters matter in Python identifiers?

Yes, upper and lower case letters have distinct characteristics in Python identifiers.

p.9
Literals in Python

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.

p.5
Identifiers in Python

What special characters are allowed in Python identifiers?

Except for the underscore (_), an identifier cannot contain any special characters.

p.12
Basic Input and Output

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.

p.4
Keywords in Python

What keyword is used to handle exceptions in Python?

finally

p.4
Keywords in Python

Which keyword is used to create a loop?

for

p.4
Keywords in Python

What keyword is used to handle errors?

try

p.4
Keywords in Python

Which keyword checks if a value is present in a tuple, list, etc.?

in

p.4
Keywords in Python

What keyword represents a null value?

None

p.11
Dynamic Typing and Variable Types

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.

p.17
Operators in Python

Give an example of an expression that produces a value when evaluated.

An example is A + 10.

p.23
Identifiers in Python

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.

p.25
Dynamic Typing and Variable Types

What will be the output of type() when the variable salary is set to 20000.50?

<class 'float'>

p.22
Multiple Assignment

What is the syntax for assigning the same value to multiple variables in Python?

a = b = c = 50

p.18
Basic Input and Output

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.

p.25
Basic Input and Output

How can you display output in Python?

You can use the print() function. For example: print('Welcome')

p.25
Basic Input and Output

What is the syntax for the print() function in Python?

print(message_to_print[,sep='string',end='string'])

p.21
Identifiers in Python

What does Lvalues refer to?

Lvalues refer to the object to which you can assign a value, specifically the memory location.

p.3
Keywords in Python

How many keywords are there in Python 3.7?

There are 33 keywords in Python programming language version 3.7.

p.9
Literals in Python

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.

p.16
Operators in Python

What does the '-=' operator do in Python?

The '-=' operator subtracts the right operand from the variable and assigns the result to the variable.

p.3
Keywords in Python

Which keyword is used to create an alias in Python?

'as' is used to create an alias.

p.12
Basic Input and Output

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.

p.5
Identifiers in Python

Are 'Myself' and 'myself' considered the same identifier in Python?

No, case matters when it comes to identifier names; they are not the same.

p.4
Keywords in Python

Which keyword is used to declare a global variable?

global

p.4
Keywords in Python

What keyword is used to define a class?

class

p.4
Keywords in Python

Which keyword is used to test if two variables are equal?

is

p.4
Keywords in Python

What keyword is used in conditional statements, same as else-if?

elif

p.4
Keywords in Python

Which statement is used to handle errors in try-except blocks?

except

p.11
Dynamic Typing and Variable Types

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.

p.21
Identifiers in Python

Provide an example of Lvalues and Rvalues in Python.

In the expression x = 100, 'x' is an Lvalue and '100' is an Rvalue.

p.21
Identifiers in Python

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.

p.8
Literals in Python

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'

p.16
Operators in Python

What is the function of Logical NOT in Python?

Logical NOT inverts the truth value of the operand.

p.9
Literals in Python

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).

p.12
Basic Input and Output

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.

p.8
Literals in Python

What will len('\ab') return?

It will return 3.

p.16
Operators in Python

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.

p.12
Basic Input and Output

What is the program to convert temperature from Fahrenheit to Celsius?

Write a program to enter temperature in Fahrenheit and convert it into Celsius.

p.4
Keywords in Python

What keyword is used to create an alias name?

as

p.4
Keywords in Python

Which keyword skips the next iteration of a loop?

continue

p.4
Keywords in Python

What keyword is used to delete an object?

del

p.4
Keywords in Python

What keyword is used to create a while loop?

while

p.5
Identifiers in Python

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.

p.16
Operators in Python

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.

p.3
Keywords in Python

What keyword is used to break out of a loop in Python?

'break' is used to break out of a loop.

p.16
Operators in Python

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.

p.3
Keywords in Python

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.

p.5
Identifiers in Python

Give an example of an invalid Python identifier.

Examples of invalid identifiers include Grade-Pay, $Amar007, and Roll No.

p.4
Keywords in Python

What keyword is used to create a conditional statement?

if

p.4
Keywords in Python

Which keyword is used in exception handling?

with

p.16
Operators in Python

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.

p.4
Keywords in Python

What logical operator represents an expression that results in not being true?

False

p.4
Keywords in Python

Which logical operator is used to negate a condition?

not

p.4
Keywords in Python

Which keyword is used when the user doesn’t want any code to execute?

pass

p.4
Keywords in Python

What keyword is used to import specific parts of a module?

from

p.4
Keywords in Python

What keyword is used to raise exceptions or errors?

raise

p.4
Keywords in Python

What keyword is used to define a function?

def

p.4
Keywords in Python

Which keyword is used in a conditional statement to provide an alternative?

else

p.5
Identifiers in Python

Give an example of a valid Python identifier.

Examples of valid identifiers include GradePay, File_12_2018, and _ismarried.

Study Smarter, Not Harder
Study Smarter, Not Harder