_IntroToPython
_IntroToPython
School Vision: To develop a purposeful and resilient institution to meet with the life-goals and aspirations of our children, parents and staff.
1. What are the key features of Python? Mention various applications along
with it.
Ans: Python is a programming language which was created by Guido Van Rossum in
1991.
Following are the key features of Python:
a) Easy to learn, read and maintain – Python has few keywords, a simple
structure and a clearly defined syntax. The Python program is fairly easy to
maintain.
b) A broad standard library – Python has a huge set of libraries with plenty of
built in programs to solve problems.
c) Interactive Mode – Python has interactive mode of coding which allows
interactive testing and debugging of code snippets.
d) Portability and Compatibility – Python uses the same interface and can run
on a variety of operating systems and hardware platforms.
e) Extendable – Programmers can add modules of programs to customize
their tools to be more efficient.
f) Databases and Scalable – Python provides interfaces for different
databases to support different large programs.
Page 1 of 5
2. What are the different modes of coding in Python?
Ans: Python shell can be used to run a program in 2 ways:
a) Interactive mode
b) Script mode
The result produced by the interpreter is the same in both modes of coding.
Interactive Mode – allows the user to interact directly with the Operating System.
This mode is useful to test small snippets of code and for beginners.
Script Mode – allows the user to create the Python program in a file and edit the
same. The Python interpreter is used to execute the content from the file. This mode
is used to code more than a few lines of code.
• Single Line code – This is indicated by using the hashtag symbol (#).
Eg: # defining a variable a
= 10
• Multi Line code – This is indicated by “ “ “ or by ‘ ‘ ‘.
Eg: ‘ ‘ ‘
This is an example code
‘‘‘
4. What are the different properties of an identifier?
Ans: An identifier is the name given to variables, functions etc. in a program. It helps
to differentiate one entity from another. The properties of an identifier
Page 2 of 5
are as follows:
• The name should begin with an uppercase or a lowercase alphabet or
an underscore sign (_). This may be followed by any combination of
characters a-z, A-Z, 0-9 or underscore (_).
• An identifier cannot start with a digit.
• It can be of any length. However, it is preferred to keep it short and
meaningful.
• Keywords or reserved words cannot be used as identifier.
• Special symbols like !, @, #, $, %, etc. in identifiers cannot be used. Eg:
_nameList, name_list, NameList, N123 are examples of identifiers.
Page 3 of 5
>>> age = input("Enter your age: ") Enter
your age: 19
Python uses the print() function to output data to standard output device — the screen.
The function print() evaluates the expression before displaying it on the screen. The
syntax for print() is:
print (value)
Example:
print("Hello") Hello
print(10*2.5) 25.0
7. What is type conversion? Explain the types of type conversion with help of an
example.
Ans: The process of converting values of one data type to another data type is called
type conversion. Python has 2 types of type conversion:
a) Implicit Type Conversion
b) Explicit Type Conversion
Implicit Type Conversion – Python automatically converts one data type to another
data type without any user intervention. Following are a few examples:
Explicit Type Conversion – Here, user can convert the data type of an object to
required data type. Predefined functions like str(), int(), float() are used to perform
explicit type conversion.
Page 4 of 5
This type of conversion is called typecasting as the user casts or changes the data type of
the objects.
Syntax: (required_data type) (expression)
a = 89
b = 89
The program with above code snippet will reserve memory for 2 variables with the names a
and b.
The variable names stand for the memory locations which hold the data.
Now, the value held by the memory location denoted by variable a is 99 now, while the value
held by the memory location denoted by the variable b is still 89.
Page 5 of 5