Chapter - 1 - Python Overview and Fundamentals
Chapter - 1 - Python Overview and Fundamentals
Contents
● Python Overview
● Fundamental
AniketGoswami
PGT – Computer Science.
Vivekananda Kendra Vidyalaya, Hurda.
1
Dist – Bhilwara
Mo. 9829906113
PYTHON OVERVIEW
Interpreter Vs Compiler
Interpreter:
Compiler:
It also converts the HLL program into machine language but the
conversion manner is different. It converts the entire HLL
program in one go, and reports all the error of the program along
with the line numbers. After all the errors are removed. The
program is recompiled. Its debugging speed is slow but execution
speed is fast.
2
Python is Interactive: This means that you can actually sit at a
Python prompt and interact with the interpreter directly to write
your programs.
History of Python:
Python was developed by Guido van Rossum in the late eighties and
early nineties at the National Research Institute for Mathematics
and Computer Science in the Netherlands.
Python Features:
3
Easy-to-maintain: Python's success is that its source code is
fairly easy-to-maintain.
Running Python:
Once you have installed python on your computer, you are ready to
work on it. You can work in python in following different ways:
Interactive mode of working means you type the command one by one
at a time, and the Python executes the given command then gives
you output.
4
In interactive mode, you can type the command in front of python
prompt >>>.
Example:
>>> 2+5
7.
Example:
Hello
>>>6*3
>>>3**3
>>>6+2*4
>>>(6+2)*4
>>>5-3-3
>>>k=5-(3-3)
if you want to save all the commands in the form of program file
and want to see all output lines together in one go. You can use
script mode of python.
5
Example:
A=10
B=20
C = A + B
Print(c)
Output:
30
Ex: Python.py
Hello World
Example:
A=10
B=20
C=A+B
print (C)
6
Python Comments
Example:
Example:
A=10
B=20
C = A + B
Print(c)
Output:
7
30
Example:
''' This
Is
Multiline comment'''
Example:
'''This is
Multiline comment'''
Python Fundamentals
8
A character represent any letter, digit, or any other sign. The
python has the following character set.
Digit - 0-9
Key Words:
Keywords are the words that can convey a special meaning to the
language compiler. These are reserved for special purpose and
must not be used as normal identifier names.
Python Identifiers:
9
An identifier is a long sequence of letter and digit.
The first character must be a letter, the underscore (_)
counts as a letter.
Upper and lower case are different. All character are
significant.
The digit 0 to 9 can be part of the identifier except for
the first character.
First character of an identifier can be character,
underscore ( _ ) but not digit.
Keyword should not be used as an identifier name.
Example:
Python Literals
I. String literals:
Example:
"Aman" , '12345'
10
Types of Strings:
Example:
>>> text1='hello'
Example:
>>>text1="hello\
user"
print (text1)
Example:
str2='''welcome
to
SSSIT'''
11
print (str2)
Output:
welcome
to
SSSIT
A Boolean literal can have any of the two values: True or False.
12
Python contains one special literal i.e., None.
>>> a=10
>>> b=None
>>>print (a)
>>>10
>>>print (b)
None
V. Literal Collections.
List:
13
The plus sign (+) is the list concatenation and asterisk (*) is
the repetition operator.
Example:
List=['aman',678,20.4,'saurav']
List1=[456,'rahul']
print (List)
print (List+List1)
Output:
[678, 20.4]
14