(PDf-4) Module 1-Python Introduction
(PDf-4) Module 1-Python Introduction
Python Keywords are special reserved words which convey a special meaning to the compiler/interpreter. Each keyword
have a special meaning and a specific operation. These keywords can't be used as variable. Following is the List of Python
Keywords.
Python Literals
I. String literals:
tring literals can be formed by enclosing a text in the quotes. We can use both single as well as double quotes for a String.
Types of Strings:
a).Single line String- Strings that are terminated within a single line are known as Single line Strings.
b).Multi line String- A piece of text that is spread along multiple lines is known as Multiple line String.
1). Adding black slash at the end of each line. 2).Using triple quotation marks:-
Eg: Eg:
1. >>> text1='hello\ >>> str2='''''welcome
user'
to
>>> text1 SSSIT'''
'hellouser' >>> print str2
>>> welcome
to
SSSIT
>>>
II.Numeric literals:
Numeric Literals are immutable. Numeric literals can belong to following four different numerical types.
Numbers( can be both Integers of unlimited Real numbers with In the form of a+bj where a forms
positive and negative) size followed by both integer and the real part and b forms the
with no fractional lowercase or uppercase fractional part eg: - imaginary part of complex
part.eg: 100 L eg: 87032845L 26.2 number. eg: 3.14j
>>> val1=10
>>> val2=None
>>> val1
10
>>> val2
>>> print val2
None
>>>
V. Literal Collections.
Collections such as tuples, lists and Dictionary are used in Python.
List:
o List contain items of different data types. Lists are mutable i.e., modifiable.
o The values stored in List are separated by commas(,) and enclosed within a square brackets([]). We can store different
type of data in a List.
o Value stored in a List can be retrieved using the slice operator([] and [:]).
o The plus sign (+) is the list concatenation and asterisk(*) is the repetition operator.
Eg:
>>> list=['aman',678,20.4,'saurav']
>>> list1=[456,'rahul']
>>> list
['aman', 678, 20.4, 'saurav']
>>> list[1:3]
[678, 20.4]
>>> list+list1
['aman', 678, 20.4, 'saurav', 456, 'rahul']
>>> list1*2
[456, 'rahul', 456, 'rahul']
>>>