0% found this document useful (0 votes)
9 views2 pages

Python

Uploaded by

Mohammed Razi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
9 views2 pages

Python

Uploaded by

Mohammed Razi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Q. What is Python? Q. What is the Role of Indentation in Python? Q.

Explain the features of python


Python is a high-level, interpreted, interactive and The identification of a block of code in Python is • Easy to Code
object-oriented scripting language. Python was done using Indentation. Most of the programming Python is a very developer-friendly language which
developed by Guido van Rossum in the late languages like C, C++, and Java use braces { } means that anyone and everyone can learn to code
eighties and early nineties at the National to define a block of code. Python, however, uses it in a couple of hours or days. The syntax rules of
Research Institute for Mathematics and Computer indentation. A code block (body of a function, loop, Python allow you to express concepts without writing
Science in the Netherlands. etc.) starts with indentation and ends with the first additional code. Python, unlike other programming
unindented line languages, emphasizes on code readability. The
Q. What is the difference between Interactive readable and clean code base will help you to main-
mode and Script Mode in Python? Q. What are the rules that we need to keep in mind tain and update the software without putting extra
In interactive mode, one command can run at a while creating Python variables? time and effort.
time and commands are not saved. Whereas in There are some rules that we need to keep in mind • Open Source and Free
Script mode, we can save all the commands in while creating Python variables. Python is an open-source programming language
the form of a program file and can see output of • Name of a variable cannot start with a number. It which means that anyone can create and contribute
all lines together. should start with either an alphabet or the under- to its development. Python has an online forum
score character. where thousands of coders gather daily to improve
Q. What is the difference between a keyword and • Variable names are always case sensitive and this language further. Along with this Python is free
an identifier? can contain alphanumeric characters and the to download and use in any operating system. As
Keywords are predefined reserved words, which underscore character. an open source programming language, Python
possess special meaning. An identifier is a unique • Reserved words cannot be used as variable helps you to curtail software development cost
name given to a particular variable, function or names. significantly. You can even use several open source
class in the program. Python frameworks, libraries and development tools
Q. What are the two categories of statements in to curtail development time without increasing de-
Q. What is the difference between an expression python? velopment cost. you can simplify and speedup web
and a statement in Python? There are two categories of statements in Python: application development by using robust Python
A statement is an instruction that the Python • Expression Statements web frameworks like Django, Flask, Pyramid, Bottle
interpreter can execute. An expression is a • Assignment Statements and Cherrypy.
combination of values, variables, operators, With the help of expressions, we perform operations • Interpreted Language
and calls to functions. Expressions need to be like addition, subtraction, concatenation etc. In oth- Python is an interpreted language i.e. interpreter
evaluated. er words, it is a statement that returns a value. executes the code line by line at a time. When you
With the help of assignment statements, we create use an interpreted language like Python, there is
Q. What are tokens in Python? How many types new variables, assign values and also change no separate compilation and execution steps. This
of tokens allowed in Python? values. makes debugging easy and thus suitable for be-
Tokens are the smallest unit of the program. ginners. Internally, Python converts the source code
There are following tokens in Python: Q. What are the different operators used in into an intermediate form called bytecodes and
• Reserved words or Keywords Python? then translates this into the native language of your
• Identifiers Python language supports the following types of specific computer and then runs it.
• Literals operators. • Cross-platform language
• Operators 1. Arithmetic Operators Python can run equally on different platforms such
• Punctuators Arithmetic operators used to perform as Windows, Linux, Unix , Macintosh etc. A Python pro-
mathematical operations gram written on a Macintosh computer will run on a
Q. What is IDLE? eg:Addition(+) , Substraction(-),Division(/),\ Linux system and vice versa. Thus, Python is a porta-
IDLE is Python’s Integrated Development and Multiplication(*), Exponentiation(**),Modulus(%) ble language. Python is an interpreted programming
Learning Environment. It allows programmers 2. Bitwise Operators language. It allows you to you to run the same code
to easily write Python code. IDLE can be used to Refers to the operators working on bit on multiple platforms without recompilation.
execute a single statement and create, modify, Eg:Binary AND(&),Binary OR(|),Binary XOR(^), • Support for GUI
and execute Python scripts. IDLE provides a Binary One’s Complement(~),Binary Left Shift(<<) GUI or Graphical User Interface is one of the key as-
fully-featured text editor to create Python scripts Binary Right Shift(>>) pects of any programming language. In python you
that include features like syntax highlighting, auto 3. Membership Operators can accelerate desktop GUI application develop-
completion, and smart indent. Refers to the operators used in validation of ment using Python GUI frameworks and toolkits like
membership of operand test in a sequence, such PyQT, PyJs, PyGUI, Kivy, PyGTK and WxPython.
Q. What is the use of type() function as strings, lists, or tuples. There are two types of • Object-Oriented language
In Python data types are classes and variables membership operators in python Python supports object oriented features. Python has
are the object of these classes. To determine what eg:in,not in all features of an object-oriented language such as
type of object declared in the program there is a 4. Identity Operators inheritance, method overriding, objects, etc. Thus it
built-in function in Python known as type(). The Used to compare the memory locations of the supports all the paradigms and has corresponding
type() function in Python returns the data type of operands, they are quite often used to determine functions in their libraries. It also supports the imple-
the object passed to it as an argument. This if the operand is of a particular type, there are two mentation of multiple inheritances,
types of identity operators in python • Simplify Complex Software Development
Q.Differentiate between Type Conversion and eg:is,is not Python is a general purpose programming language.
Type Casting 5. Comparison Operators Hence, you can use the programming language for
Type Conversion is the conversion of object from Also known as Relational operators, these operators developing both desktop and web applications. Also,
one data type to another data type. Implicit Type are used in determining the relation between the you can use Python for developing complex scientific
Conversion is automatically performed by the operand on either side of the operator and numeric applications. Python is designed with
Python interpreter. Explicit Type Conversion is also eg:==,!=,<>,>,<,>=,<= features to facilitate data analysis and visualization.
called Type Casting, the data types of objects are 6. Assignment Operators Many Python developers even use Python to accom-
converted using predefined functions by the user. Refer as the name suggests is used to declare as- plish artificial intelligence (AI) and natural language
signments to the operands, following are the types processing tasks.
Q. Differentiate between Mutable and Immutable of assignment operators in python.
Types eg: Equal to(=), Add AND(=+),
Data are stored in a computer’s memory for pro- Subtract AND(-=), Multiply AND(*=),
cessing. Some of these values can be modified Divide AND(/=), Modulus AND(%=)
during processing, but contents of others can’t 7. Logical Operators
be altered once they are created in the memory. These operators are used to perform similar oper-
Numbers, strings, and Tuples are immutable, ations as that of logical gates, there are 3 types of
which means their contents can’t be altered after logical operators in python.
creation. On the other hand, items in a List or eg: Logical AND(and), Logical OR(or),
Dictionary object can be modified. It is possible to Logical NOT(not)
add, delete, insert, and rearrange items in a list or
dictionary. Hence, they are mutable objects.
Q. Explain different data type used in python Q.Explain IF statement in Python? Q.What is Looping Statements in python?
Python provides various standard data types that IF statement will execute block of statements only The flow of the programs written in any program-
define the storage method on each of them. if the condition is true. ming language is sequential by default. Sometimes
The data types defined in Python are: Syntax: we may need to alter the flow of the program. The
1. Numbers if test expression: execution of a specific code may need to be repeat-
Number stores numeric values. The integer, float, statement(s). ed several numbers of times. For this purpose, The
and complex values belong to a Python Numbers In Python, the body of the if statement is indicated programming languages provide various types of
data-type. Python supports three types of by the indentation. The body starts with an inden- loops which are capable of repeating some specific
numeric data. tation and the first unindented line marks the end. code several numbers of times.
• Int – It contains positive or negative whole Python interprets non-zero values as True. None while loop:
numbers (without fraction or decimal). and 0 are interpreted as False The while loop in Python is used to iterate over a
• Float - Float is used to store floating-point eg: num = 3 block of code as long as the test expression
numbers if num > 0: (condition) is true. We generally use this loop when
• complex - A complex number contains an print(num, “is a positive number.”) we don’t know the number of times to iterate
ordered pair beforehand.
2. Sequence Type Q.Explain IF … ELSE statement? Syntax:
• String: - The string can be defined as the se- The if-else statement checks the expression and while test_expression:
quence of characters represented in the executes the if block when the expression is True Body of while
quotation marks. otherwise it will execute the else block of code. In the while loop, test expression is checked first. The
eg: A=”Python programming” Syntax: body of the loop is entered only if the test_expres-
• List: - A list object is an ordered collection of one if test expression: sion evaluates to True. After one iteration, the test
or more data items, not necessarily of the same Body of if expression is checked again. This process continues
type. The items stored in the list are separated else: until the test_expression evaluates to False.
with a comma (,) and enclosed within square Body of else
brackets []. The if..else statement evaluates test expression
eg: L= [34, 2.5, True, ”Apple”] and will execute the body of if only when the test
• Tuple: -A Tuple object is an ordered collection condition is True. If the condition is False, the body
of one or more data items, not necessarily of the of else is executed. Indentation is used to separate
same type. The items of the tuple are separated the blocks.
with a comma (,) and enclosed in parentheses (). Eg: num = 3
eg: T= (25, True, 3.5,”Orange”) if num >= 0:
3. Dictionary print(“Positive or Zero”)
Dictionary is an unordered set of a key-value pair else:
of items. Key can hold any primitive data type, print(“Negative number”)
whereas value is an arbitrary Python object. The
items in the dictionary are separated with the Q.Explain if...elif...else Statement
comma (,) and enclosed in the curly braces {}. The elif statement helps you to check multiple ex-
eg: D={1:”Jan”, 2:”Feb” , 3:”Mar”} pressions and it executes the code as soon as one
4. Boolean of the conditions evaluates to True.
Boolean type provides two built-in values, True Syntax: Example: n = 10
and False. These values are used to determine the if test expression: sum = 0
given statement true or false. Body of if i=1
eg: B=True elif test expression:
5. Set Body of elif while i <= n:
Python Set is the unordered collection of the data else: sum = sum + i
type. It is mutable and has unique elements. In Body of else i = i+1 # update counter
set, the order of the elements is undefined. The The elif is short for else if. It allows us to check for
set is created by using a built-in function set(), multiple expressions. If the condition for if is False, # print the sum
or a sequence of elements is passed in the curly it checks the condition of the next elif block and so print(“The sum is”, sum
braces and separated by the comma. on. If all the conditions are False, the body of else is
eg: S=set(23,45,67) executed. The if block can have only one else block. Q.Explain range function?
But it can have multiple elif blocks. The range() function is a built-in-function used in
Q. Specify the area where Python can be applied. Flowchart: python, it is used to generate a sequence of
Areas where Python can be applied: numbers.
Web Applications Syntax:
We can use Python to develop web applications. The syntax of range() function is shown below:
It provides libraries to handle internet protocols range(start, stop, step)
such as HTML and XML etc. Start: Optional — An integer number that specifies
Desktop GUI Applications where to start (Default value is 0)
The GUI stands for the Graphical User Interface, Stop: Required — An integer number that specifies
which provides a smooth interaction to any where to stop.
application. Python provides a Tk GUI library to Step: Optional — An integer number that specifies
develop a user interface how much to increment the number (Default value
Console-based Application is 1)
Console-based applications run from the
command-line or shell. These applications are
computer program which are used commands to
execute. Python can develop this kind of eg: num=3
application very effectively. if num > 0:
Scientific and Numeric print(“Positive number”)
Python language is the most suitable language elif num == 0:
for Artificial intelligence or machine learning. It print(“Zero”)
consists of many scientific and mathematical else:
libraries, which makes easy to solve complex print(“Negative number”)
calculations.
Business Applications Q.Explain nested if statements in python
E-commerce and ERP are an example of a busi- We can have a if...elif...else statement inside an-
ness application. This kind of application requires other if...elif...else statement. This is called nesting
extensively, scalability and readability, and Python in computer programming. Any number of these
provides all these features. statements can be nested inside one another.
Audio or Video-based Applications Indentation is the only way to figure out the level
Python is flexible to perform multiple tasks and of nesting.
can be used to create multimedia applications. Example: num = float(input(“Enter a number: “))
The few multimedia libraries are Pyglet ,QT if num >= 0:
Phonon etc. if num == 0:
print(“Zero”)
else:
print(“Positive number”)
else:
print(“Negative number”)

You might also like