0% found this document useful (0 votes)
4 views

_IntroToPython

The document provides an introduction to Python, detailing its key features, applications, and modes of coding. It explains concepts such as comments, identifiers, variable naming rules, input/output functions, and type conversion. Additionally, it defines variables and illustrates their usage with examples.

Uploaded by

sreedharsravani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

_IntroToPython

The document provides an introduction to Python, detailing its key features, applications, and modes of coding. It explains concepts such as comments, identifiers, variable naming rules, input/output functions, and type conversion. Additionally, it defines variables and illustrates their usage with examples.

Uploaded by

sreedharsravani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

(Under the supervision of the Ministry of Education and Higher Education)

School Vision: To develop a purposeful and resilient institution to meet with the life-goals and aspirations of our children, parents and staff.

Unit 5 Introduction to Python

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.

Following are the applications of Python:

a) Desktop GUI applications


b) Business Applications
c) Games and 3D Graphics
d) Database Access
e) Software Development
f) Web and Internet Development

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.

3. What are comments in python? List down various types of comments.


Ans:
• A comment in Python is a line of code which does not affect the outcome of a
code.
• A Comment is ignored by the interpreter during the execution of a
program.
• Comments are for the programmer’s reference.
• Comments enhance the readability of the code and the understanding of the
programmer.

Comments are of 2 types:

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

5. What are the rules for naming of variables and constants?


Ans: Following are the rules for naming variables and constants:
• Create names that make sense.
• Use camelCase notation to declare a variable i.e., starts with a lowercase
letter. Eg: newNum
• Use capital letters for declaring constants. Eg: PI
• Constants and variables should have a combination of letters in lowercase or
uppercase or digits or an underscore.
• Special symbols like ! , @ , # , $ , % etc cannot be used in variables and
constants.

6. Explain python input and output with an example?


Ans: In Python, the input() function is used for taking values entered by input device
such as a keyboard. The input() function prompts user to enter data. It accepts all user
input (whether alphabets, numbers or special character) as string.
The syntax for input() is:
variable = input(<String>)
Example :
>>>fname = input("Enter your first name: ") Enter
your first name: Arnab

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:

Code Output Explanation


a) a = 10 Type Error The output shows an error which says that we
b = “Hello” cannot add integer and string variable
print(a+b) types using implicit conversion.

b) c = ‘Here’ HereHereHere The output shows the string is printed 3


N= 3 times when a multiply operator is used with a
Print (c * N)
string.
c) X = True 11 Here the output shows that the Boolean value
Y = 10 of X is converted to integer and as it is true, it
Print(X + Y) is considered as 1 and added to
value of Y.

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)

Eg: aNum = int(input(“enter a 2 digit number :”))


Here what is entered by the user using the keyboard through the input function is in string
format. To convert the string into integer data type int() function is used.

8. What is a variable? Give example.


Ans: A variable is a named location to store data in the memory. It is a container which holds
data that can be changed later in the program.

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.

The values of the variables can be changed in the program a = 99

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy