Which of the following is a valid Python identifier?
Introduction to Python — Important Questions
SUMMARY: This chapter introduces students to the basics of Python programming, including its syntax and fundamental concepts.
KEY TOPICS: Python syntax, variables, data types, operators, input/output functions, conditional statements, loops, functions, error handling, Python IDEs
Which keyword is used to define a function in Python?
Check answerHide answer
The output of print(7 // 2) in Python is:
Check answerHide answer
Lists in Python are:
Check answerHide answer
Tuples in Python are:
Check answerHide answer
Differentiate between mutable and immutable data types in Python.
List any three rules for naming a variable in Python.
Differentiate between list and tuple in Python.
What is the difference between print() and input()?
How are dictionaries different from lists in Python?
Write a Python program to find the largest of three numbers using if-elif-else.
Write a Python program to compute the factorial of a number using a for loop.
Discuss different types of operators in Python with examples.
Write a Python function that takes a list and returns the sum and average of its elements.
Write a Python program to count the number of vowels and consonants in a string.
Differentiate between mutable and immutable data types in Python in tabular form.
Assertion (A): Python is dynamically typed.
Reason (R): Variables do not need to be declared with a type.
Show explanationHide explanation
Assertion (A): Indentation is mandatory in Python.
Reason (R): It defines blocks of code.
Show explanationHide explanation
Assertion (A): Strings are immutable in Python.
Reason (R): Once created their characters cannot be changed.
Show explanationHide explanation
Assertion (A): Lists can store elements of different data types.
Reason (R): Python lists are heterogeneous.
Show explanationHide explanation
Assertion (A): Dictionaries are unordered collections.
Reason (R): Items are accessed by key not position.
Show explanationHide explanation
Statement 1: A list is created using square brackets.
Statement 2: Lists support indexing and slicing.
Show answerHide answer
Statement 1: A tuple is created using parentheses.
Statement 2: Tuples are faster than lists for iteration.
Show answerHide answer
Statement 1: A dictionary stores key-value pairs.
Statement 2: Keys must be unique and immutable.
Show answerHide answer
Statement 1: Comments in Python begin with #.
Statement 2: They are ignored by the interpreter.
Show answerHide answer
Statement 1: The input() function returns a string by default.
Statement 2: Use int() or float() for type conversion.
Show answerHide answer
-
To assign a value to a variable in Python use:A=B==C=:Dis
-
What does input() return by default?AintBfloatCstrDbool
-
Write the complete Python program with proper type conversion.
Show answersHide answers
Identify the data type of each Python literal.
| Literal | Type |
|---|---|
| 42 | ? |
| 3.14 | ? |
| 'Hello' | ? |
| True | ? |
| [1, 2, 3] | ? |
| (1, 2, 3) | ? |
Predict the output of each Python expression.
| Expression | Output |
|---|---|
| 3 + 2 * 4 | ? |
| 10 / 3 | ? |
| 10 // 3 | ? |
| 10 % 3 | ? |
| 2 ** 3 | ? |
| 'ab' * 3 | ? |
Predict the output of each list operation.
| Operation on a = [1, 2, 3] | Result |
|---|---|
| a.append(4) | ? |
| a.extend([5, 6]) | ? |
| a.insert(0, 0) | ? |
| a.remove(3) | ? |
| a.pop() | ? |
Predict the output of each string operation.
| s = 'Hello World' | Result |
|---|---|
| len(s) | ? |
| s.upper() | ? |
| s[0:5] | ? |
| s[-1] | ? |
| s.split() | ? |
| 'World' in s | ? |
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
Study the Python operator precedence diagram and answer:
-
Which has the HIGHEST precedence in Python?A**B* / //C( )Dnot
-
Which has the LOWEST precedence?AandBorCnotD==
-
Discuss Python operator precedence and how parentheses override it.
Show answersHide answers
Study the list vs tuple vs dict comparison and answer:
-
Which is IMMUTABLE?AlistBtupleCdictDAll
-
Which uses curly braces { } and indexes by key?AlistBtupleCdictDset
-
Compare list tuple and dict on five features.
Show answersHide answers
Make a full Informatics Practices 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