Which of the following is a valid Python identifier?
Introduction to Python — Important Questions
SUMMARY: The chapter introduces the basics of Python programming, including its syntax, semantics, and fundamental programming constructs.
KEY TOPICS: Python syntax, variables and data types, operators, control structures, functions, input and output operations
The output of print(type(3.14)) is:
Check answerHide answer
Which of the following is NOT a Python keyword?
Check answerHide answer
The result of 7 // 2 in Python is:
Check answerHide answer
The operator used for exponentiation in Python is:
Check answerHide answer
What is the correct way to declare a variable in Python?
Check answerHide answer
Which of the following data types is immutable in Python?
Check answerHide answer
What will be the output of the following code: print(5 * 2 ** 3) ?
Check answerHide answer
Which of the following operators is used for logical AND in Python?
Check answerHide answer
How do you start a comment in Python?
Check answerHide answer
What is the output of the following code: print('Hello' + 'World')?
Check answerHide answer
Which of the following is a valid way to define a function in Python?
Check answerHide answer
What will the following code snippet return: len('Python')?
Check answerHide answer
What will be the output of the following code: print(10 % 3)?
Check answerHide answer
Which of the following statements is true about Python lists?
Check answerHide answer
Differentiate between mutable and immutable data types in Python with two examples each.
List any three rules for naming a variable in Python.
What is the difference between = and == in Python?
Explain the use of the input() function with one example.
Differentiate between integer and float types in Python.
What are the basic data types available in Python?
View sample solutionHide solution
Explain the concept of operators in Python. Provide examples of at least two types of operators.
View sample solutionHide solution
What is the purpose of control structures in Python? Give an example of a control structure.
View sample solutionHide solution
Describe the syntax for defining a function in Python. What is the significance of the 'return' statement?
View sample solutionHide solution
How can you take multiple inputs from a user in Python? Provide a code snippet as an example.
View sample solutionHide solution
Differentiate between mutable and immutable data types in Python in tabular form with examples.
Compare for loop and while loop in Python with the help of a table.
Differentiate between break and continue statements in tabular form.
Compare = and == in Python with the help of a table.
Differentiate between print() and input() functions in Python in tabular form.
Write a Python program to compute the area and circumference of a circle given its radius. Use input() and round the output to 2 decimal places.
Assertion (A): Python is dynamically typed.
Reason (R): Variables do not need to be declared with a type before use.
Show explanationHide explanation
Assertion (A): Indentation is mandatory in Python.
Reason (R): It defines blocks of code instead of using braces.
Show explanationHide explanation
Assertion (A): Python is an interpreted language.
Reason (R): The interpreter executes Python code line by line.
Show explanationHide explanation
Assertion (A): The print() function ends with a newline by default.
Reason (R): The default value of the end parameter is '\n'.
Show explanationHide explanation
Assertion (A): Boolean values in Python are True and False.
Reason (R): They are subtypes of the integer type with values 1 and 0.
Show explanationHide explanation
Assertion (A): In Python, a variable can hold values of different data types during the execution of a program.
Reason (R): This is due to Python's dynamic typing feature.
Show explanationHide explanation
Assertion (A): The syntax for defining a function in Python requires the use of the keyword 'def'.
Reason (R): This keyword is used to indicate the start of a function definition.
Show explanationHide explanation
Assertion (A): Python supports both single-line and multi-line comments.
Reason (R): Single-line comments start with a hash symbol (#), while multi-line comments are enclosed in triple quotes.
Show explanationHide explanation
Statement 1: Python uses indentation to define code blocks.
Statement 2: A consistent number of spaces (usually 4) is the convention.
Show answerHide answer
Statement 1: Comments in Python begin with the # symbol.
Statement 2: They are ignored by the interpreter.
Show answerHide answer
Statement 1: The input() function reads a string from the user.
Statement 2: It must be type-converted if a number is needed.
Show answerHide answer
Statement 1: Operator precedence in Python follows mathematical rules.
Statement 2: Parentheses can be used to override the default precedence.
Show answerHide answer
Statement 1: Type conversion can be implicit or explicit.
Statement 2: int() float() str() are explicit conversion functions.
Show answerHide answer
Statement 1: In Python, a variable name can start with a digit.
Statement 2: The float data type can represent decimal numbers.
Show answerHide answer
Statement 1: The 'if' statement in Python is used to create loops.
Statement 2: Python supports multiple data types including lists and tuples.
Show answerHide answer
Statement 1: The 'while' loop in Python executes as long as a condition is true.
Statement 2: Functions in Python can return multiple values using tuples.
Show answerHide answer
-
To assign a value to a variable in Python use:A=B==C=:Dis
-
If the user enters 5000 for principal what type does input() return by default?AintBfloatCstrDbool
-
Write the complete Python program with type-conversion error handling.
Show answersHide answers
Identify the data type of each Python literal.
| Literal | Type |
|---|---|
| 42 | ? |
| 3.14 | ? |
| 'Hello' | ? |
| True | ? |
| [1, 2, 3] | ? |
| (1, 2, 3) | ? |
| {'a':1} | ? |
Predict the output of each Python expression.
| Expression | Output |
|---|---|
| 3 + 2 * 4 | ? |
| 10 / 3 | ? |
| 10 // 3 | ? |
| 10 % 3 | ? |
| 2 ** 3 | ? |
| 'a' + 'b' | ? |
| 'ab' * 3 | ? |
Identify the result of each comparison in Python.
| Comparison | Result |
|---|---|
| 5 == 5 | ? |
| 5 == 5.0 | ? |
| 5 is 5.0 | ? |
| '5' == 5 | ? |
| [1, 2] == [1, 2] | ? |
| [1, 2] is [1, 2] | ? |
Study the table of Python operators and answer:
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Addition or concat | 3 + 5 | 8 |
| ** | Exponent | 2 ** 3 | 8 |
| // | Floor div | 7 // 2 | 3 |
| % | Modulus | 7 % 2 | 1 |
| == | Equality | 5 == 5 | True |
-
The output of 7 // 2 in Python is:A2B3C3.5D4
-
The output of 2 ** 3 is:A8B9C6D5
-
Discuss any five categories of operators in Python with examples.
Show answersHide answers
Study the Python data type hierarchy and answer:
-
Which of the following is a MUTABLE data type?AintBlistCstrDtuple
-
Which is an immutable sequence?AlistBdictCtupleDset
-
Differentiate between mutable and immutable data types in Python with examples.
Show answersHide answers
Make a full Computer Science paper on Introduction to Python.
Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.
Generate your paper — free