Part B Unit 4 Introduction to Python
Part B Unit 4 Introduction to Python
A computer program is a collection of instructions that perform a specific task when executed by a
computer. The purpose of programs is to make computer programs run faster, safer, and more
efficiently. Programs do everything in a computer: they read and write data, manage memory, and
perform calculations. They are the building blocks of the operating system, the software that runs
our most important functions, and the programs we write ourselves. One of the most important
programs on a computer is the operating system, which performs basic functions such as memory
management and file management.
Programming languages such as C++, Java, Python, and Ruby are used to construct programmes.
These are human-readable and writable high-level programming languages.
Applications of Python
Python is a high-level, general-purpose programming language. It is different from other languages
such as C and Java that are designed to be compiled to machine code. Python is easy to learn and
can be used to write virtually anything that can be described in code.
s=1+2+3+\
Using Continuation Character (/) 4+5+6+\
7+8+9
Using Parentheses () n = (1 * 2 * 3 + 4 – 5)
footballer = [‘MESSI’,
Using Square Brackets [] ‘NEYMAR’,
‘SUAREZ’]
x = {1 + 2 + 3 + 4 + 5 + 6 +
Using braces {}
7 + 8 + 9}
+ Addition 20 + 20 40
– Subtraction 30 – 10 20
/ Division 30 / 10 20
// Integer Division 25 // 10 2
% Remainder 25 % 10 5
** Raised to power 3 ** 2 9
Assignment Operator
When assigning values to variables, assignment operators are used.
Operator Expression Equivalent to
= x=10 x = 10
+= x += 10 x = x + 10
-= x -= 10 x = x – 10
*= x *= 10 x = x * 10
/= x /= 10 x = x / 10
Comparison Operator
The values are compared using comparison operators or relational operators. Depending on the
criteria, it returns True or False.
Operator Meaning Expression Result
20 < 50 False
10 < 40 True
== Equal To 5 == 5 True
5 == 6 False
35 != 35 False
Logical Operator
Logical operators are used to combine the two or more then two conditional statements –
Operator Meaning Expression Result
Type Conversion
Type conversion is the process of converting the value of one data type (integer, text, float, etc.) to
another data type. There are two types of type conversion in Python.
1. Implicit Type Conversion
2. Explicit Type Conversion
Implicit Type Conversion
Python automatically changes one data type to another via implicit type conversion. There is no
need for users to participate in this process.
Example :
x=5
y=2.5
z=x/z
In the above example, x is containing integer value, y is containing float value and in the variable z
will automatically contain float value after execution.
Explicit Type Conversion
Users transform the data type of an object to the required data type using Explicit Type Conversion.
To do explicit type conversion, we employ predefined functions such as int(), float(), str(), and so on.
Because the user casts (changes) the data type of the objects, this form of conversion is also known
as typecasting.
Example : Birth_day = str(Birth_day)
Python Input and Output
Python Output Using print() function
To output data to the standard output device, we use the print() method (screen).
Data can also be saved to a file. The following is an example.
Example :
a = “Hello World!”
print(a)
Output – Hello World!
Python User input
In python, input() function is used to take input from the users.
Hide Answer ⟵
c. Guido van Rossum
2. Python supports which types of programming?
a. object-oriented programming
b. structured programming
c. functional programming
d. All of the mentioned
Hide Answer ⟵
d. All of the above
3. When it comes to identifiers, is Python case sensitive?
a. No
b. Yes
c. Machine dependent
d. None of the mentioned
Hide Answer ⟵
b. yes
4. Which of the following is the valid Python file extension?
a. .python
b. .pl
c. .py
d. .p
Hide Answer ⟵
c. .py
5. All keywords in Python are in _________.
a. Capitalized
b. lower case
c. UPPER CASE
d. None of the mentioned
Hide Answer ⟵
d. None of the mentioned
6. In Python, which of the following characters is used to create single-line comments?
a. //
b. #
c. !
d. /*
Hide Answer ⟵
b. #
7. Which of the following statements about variable names in Python is correct?
a. Underscore and ampersand are the only two special characters allowed
b. Unlimited length
c. All private members must have leading and trailing underscores
d. None of the mentioned
Hide Answer ⟵
b. Unlimited length
8. What is the maximum length of an identifier that can be used?
a. 16
b. 32
c. 64
d. None of these above
Hide Answer ⟵
d. None of these above
9. When was the Python programming language created?
a. 1995
b. 1972
c. 1981
d. 1989
Hide Answer ⟵
d. 1989
Hide Answer ⟵
c. C
11. In the Python language, which of the following is not a keyword?
a. Val
b. Raise
c. Try
d. With
Hide Answer ⟵
a. val
12. In the Python language, which of the following statements is correct for variable names?
a. All variable names must begin with number.
b. Unlimited length
c. The variable name length is a maximum of 2 characters.
d. All of the above
Hide Answer ⟵
b. Unlimited length
13. A computer ___________ is a collection of instructions that perform a specific task when
executed by a computer.
a. Program
b. Code
c. Code Body
d. None of the above
Hide Answer ⟵
a. Program
14. Why is Python such a widely used programming language?
a. Easy to learn
b. Portability and compatibility
c. A Broad Standard Library
d. All of the above
Hide Answer ⟵
d. All of the above
15. What are the various applications that Python supports?
a. Web and Desktop GUI Application
b. Database Access
c. Games and 3D Graphics
d. All of the above
Hide Answer ⟵
d. All of the above
16. Python is a _________ programming language, which means it runs on a variety of platforms
including Windows, MacOS, Linux, and the Java and.NET Virtual machines.
a. Cross-platform
b. Single-platform
c. Code-platform
d. None of the above
Hide Answer ⟵
a. Cross-platform
17. Python ___________ must be installed on our machine in order to run a Python programme.
a. Interpreter
b. Compiler
c. Assembler
d. All of the above
Hide Answer ⟵
a. Interpreter
18. IDE stands for ______________.
a. Integrated Development Environment
b. Internal Develop Environment
c. Inside Development Environment
d. None of the above
Hide Answer ⟵
a. Integrated Development Environment
19. IDLE stands for ____________.
a. Integrated Development and Learning Environment
b. Internal Develop and Learning Environment
c. Inside Development and Learning Environment
d. None of the above
Hide Answer ⟵
a. Integrated Development and Learning Environment
20. IDE helps to __________ python programs in a single interface.
a. Edit, Run
b. Browse
c. Debug
d. All of the above
Hide Answer ⟵
d. All of the above
21. What are the two methods for using a Python shell?
a. Interaction Mode, Sub Mode
b. Interactive Mode, Script Mode
c. Shell Mode, Python Mode
d. None of the above
Hide Answer ⟵
b. Interactive Mode, Script Mode
22. You can add a programme in __________ in Interactive Mode.
a. Multiple Line
b. Single Line
c. Two Line
d. None of the above
Hide Answer ⟵
b. Single Line
23. You can add a programme in __________ in Script Mode.
a. Multiple Line
b. Single Line
c. Two Line
d. None of the above
Hide Answer ⟵
a. Multiple Line
24. Instructions written in the source code for execution are called ___________.
a. Statements
b. Sentence
c. Both a) and b)
d. None of the above
Hide Answer ⟵
a. Statements
25. Statements in Python can be extended to one or more lines using _____________.
a. braces{}
b. Parentheses()
c. Square Brackets[]
d. All of the above
Hide Answer ⟵
d. All of the above
26. A _________ is a piece of text that doesn’t impact the outcome of a programme; it’s just a way
to tell someone what you’ve done in a programme or what’s going on in a block of code.
a. Statement
b. Comments
c. Nodes
d. None of the above
Hide Answer ⟵
b. Comments
27. _________ are the reserved words in Python used by the Python interpreter to recognize the
structure of the program.
a. Keywords
b. Identifiers
c. Comments
d. None of the above
Hide Answer ⟵
a. Keywords
28. An ____________ is a name given to entities like class, functions, variables, etc.
a. Keywords
b. Identifiers
c. Comments
d. None of the above
Hide Answer ⟵
b. Identifiers
29. Python is a ____________ language.
a. Upper case
b. Small case
c. Case-sensitive
d. None of the above
Hide Answer ⟵
c. Case-sensitive
30. In the Identifier, Multiple words can be separated using an ___________.
a. Underscore
b. Parentheses
c. Bracket
d. None of the above
Hide Answer ⟵
a. Underscore
31. An identifier cannot start with a __________.
a. Numbers
b. Character
c. Underscore
d. None of the above
Hide Answer ⟵
a. Numbers
32. ___________ cannot be used as identifiers.
a. Numbers
b. Characters
c. Keywords
d. None of the above
Hide Answer ⟵
c. Keywords
33. Which special symbol is not allowed in Identifier.
a. !, @
b. #, $
c. %
d. All of the above
Hide Answer ⟵
d. All of the above
34. A ___________ is a name location used to store data in the memory.
a. Variable
b. Keywords
c. Statement
d. None of the above
Hide Answer ⟵
a. Variable
35. A _________ is a type of variable whose value cannot be changed.
a. Constant
b. Statement
c. Identifier
d. None of the above
Hide Answer ⟵
a. Constant
36. ________ characters are possible to declare a constant.
a. Small Character
b. Capital Character
e. Both a) and b)
f. None of the above
Hide Answer ⟵
e. Both a) and b)
37. In python everything’s an ___________.
a. Variable
b. Constant
d. Object
e. None of the above
Hide Answer ⟵
d. Object
38. What are the different types of numerical data types?
a. Integer & Long
b. Float / Floating point
c. Both a) and b)
d. None of the above
Hide Answer ⟵
c. Both a) and b)
39. Numbers with fractions or decimal points are called ________ datatype.
a. Integer
b. String
c. Float
d. None of the above
Hide Answer ⟵
c. Float
40. A ___________ is an ordered collection of items, indexed by positive integers. It is a
combination of mutable and non-mutable data types.
a. Sequence
b. Integer
c. Float
d. None of the above
Hide Answer ⟵
a. Sequence
41. What are the different types of Sequence data types in python?
a. String
b. Lists
c. Tuples
d. All of the above
Hide Answer ⟵
d. All of the above
42. String is an ordered sequence of letters/characters. They are enclosed in single quotes (‘ ‘) or
double (“ “).
a. String
b. Integer
c. Float
d. None of the above
Hide Answer ⟵
a. String
43. ___________ are a sequence of values of any type, and are indexed by integers. They are
immutable. Tuples are enclosed in ().
a. String
b. Lists
c. Tuples
d. All of the above
Hide Answer ⟵
c. Tuples
44. __________is an unordered collection of values, of any type, with no duplicate entry.
a. String
b. Set
c. Dictionaries
d. None of the above
Hide Answer ⟵
b. Set
45. ____________is an unordered collection of key-value pairs. It is generally used when we have
a
huge amount of data.
a. String
b. Set
c. Dictionaries
d. None of the above
Hide Answer ⟵
c. Dictionaries
46. _________ are special symbols which represent computation. They are applied on operand(s),
which can be values or variables.
a. Operators
b. Operand
c. Declaration
d. None of the above
Hide Answer ⟵
a. Operators
47. Operators are categorized as _____________.
a. Arithmetic
b. Relational
c. Logical and Assignment
d. All of the above
Hide Answer ⟵
d. All of the above
48. _________ function is used to given output in python.
a. printf()
b. print()
c. scan()
d. None of the above
Hide Answer ⟵
b. print()
49. _________ function is used to take input from the user in python.
a. Input()
b. Insert()
c. Store()
d. None of the above
Hide Answer ⟵
a. Input()
Hide Answer ⟵
d. Both a) and b)
51. Python automatically converts one data type to another datatype. This process is known as
___________.
a. Implicity Type Conversion
b. Explicity Type Conversion
c. Py Type Conversion
d. Both a) and b)
Hide Answer ⟵
a. Implicity Type Conversion
52. Convert the data type of an object to required data type. We use the predefined functions like
int(), float(), str(), etc to perform ____________.
a. Implicity Type Conversion
b. Explicity Type Conversion
c. Py Type Conversion
d. Both a) and b)
Hide Answer ⟵
b. Explicity Type Conversion
3. Python includes a large library of built-in functions that can be used to tackle a wide range of
problems.
4. Python features an interactive mode that enables interactive testing and debugging of code
snippets.
5. Python runs on a wide range of operating systems and hardware platforms, with the same user
interface across all of them.
6. We can use the Python interpreter to add low-level models. These models allow programmers to
make their tools more efficient by customizing them.
7. Python includes interfaces to all major open source and commercial databases, as well as a more
structured and robust framework and support for big systems than shell scripting.
9. What is Variable?
Answer – In a computer language, a variable is a memory area where a value is stored. A variable in
Python is created when a value is assigned to it. In Python, declaring a variable does not necessitate
any additional commands.
10. What are the different rules for declaring the Variable?
Answer – The rules for declaring variable are –
1. A number cannot be used as the first character in the variable name. Only a character or an
underscore can be used as the first character.
2. Python variables are case sensitive.
3. Only alpha-numeric characters and underscores are allowed.
4. There are no special characters permitted.
1. Numbers
2. Sequences
3. Sets
4. Maps