Introduction
Introduction
Introduction
(Identifiers,Keywords,Data Types, Type Conversion)
2. Operators
3.Input/ Output Systems
4.Control Statements
5.Pattern Programs
6.Strings
7.Lists
8.Tuples
9.Sets
10.Dictionary
11.Functions
12. Modules ,Packages
1.Introduction
IDENTIFIERS
• An identifier is a name given to entities like
class, functions, variables, etc.
• It helps to differentiate one entity from
another.
IDENTIFIERS
Rules for writing identifiers
• Alphabet Symbols lowercase (a to z) or uppercase (A to Z) or digits (0 to
9) or an underscore _.
if True:
print ("True")
else:
print ("False")
Quotation in Python
Python accepts single ('), double (") and triple
(''' or """) quotes to denote string literals, as
long as the same type of quote starts and ends
the string.
The triple quotes are used to span the string
across multiple lines. For example, all the
following are legal
Quotation in Python
word = 'word'
sentence = "This is a sentence."
paragraph = """This is a paragraph. It is made up
of multiple lines and sentences."""
Comments in Python
A hash sign (#) that is not inside a string literal is
the beginning of a comment.
Here, 100, 1000.0 and "John" are the values assigned to counter,
miles, and name variables, respectively. This produces the
following result −
100
1000.0
John
Multiple Assignment
Python allows you to assign a single value to
several variables simultaneously.
example
a=b=c=1
int
a=5
print(a, "is of type", type(a))
Float
a = 2.0
print(a, "is of type", type(a))
Python Strings
t = (5,'program', 1+3j)
# t[1] = 'program‘
print("t[1] = ", t[1])
# t[0:3] = (5, 'program', (1+3j))
print("t[0:3] = ", t[0:3])
t[0] = 10
Python Set
a = {1,2,2,3,3,3}
print(a)
Since, set are unordered collection, indexing has no meaning.
Hence, the slicing operator [] does not work.
a = {1,2,3}
a[1]
Python Dictionary
d = {101:‘AAA',102:‘BBB',103:‘CCC'}
• Duplicate keys are not allowed but values can be
duplicated.
• If we are trying to insert an entry with duplicate key then
old value will be replaced with new value.
Python Dictionary
d = {101:‘AAA’,102:’BBB’,103:‘CCC’}
d[101]=‘aaa’
Print(d)
We use key to retrieve the respective value. But
not the other way around.
Print(d[‘aaa’])
Range Data Type:
• range Data Type represents a sequence of numbers.
• The elements present in range Data type are not modifiable. i.e range Data type is immutable.
• Form-1:
range(10)
generate numbers from 0 to 9
Eg: r = range(10)
for i in r : print(i)
• Type Conversion
The process of converting the value of one
data type (integer, string, float, etc.) to
another data type is called type conversion.
Python has two types of type conversion.
Implicit Type Conversion
Explicit Type Conversion
Python Type Conversion and Type Casting
num_int = 123
num_str = "456“
print("Data type of num_int:",type(num_int))
print("Data type of num_str:",type(num_str))
print(num_int+num_str)
Python Type Conversion and Type Casting