Chapter -3 Python Fundamentals Part -1-2
Chapter -3 Python Fundamentals Part -1-2
Python Fundamentals 1
Keywords
Identifiers
Literals Operators
• It is a collection of valid characters that we can either
enter through keyboard as input or display as output
on monitor.
• They can be present in the form of
• Letters A–Z,a–z
• Digits 0–9
• Special Symbols +,@,$
• Whitespaces etc
space created using space bar key,
• Other Characters tab key, enter key
Characters that are used in
other languages.
• Python supports two types of character set. These are
Character Set
ASCII Unicode
(American standard
code for information (Universa
interchange) l Coding)
• It consist of total 128 characters
• It consist of letters from English language only
• It can be used in CUI as well as GUI programming
• It is a 7 bit code.
• It contains data in the range of 0 – 127 (128)
• A – Z (65 – 90)
• a – z (97 – 122)
• 0 – 9 (48 – 57 )
• Rest are special symbols such as &, @, * etc
• It consist of approx. 1,00,000 characters.
• It consist of letters from almost all the known languages on
Earth
• It is the default character set of Python 3
• It’s size is not fix
• It contains all the known characters of the world such as
• राम
•ஹ ஹ
• ڟښ
•㋀
• And all the characters that are present in ASCII are also available in
Unicode too
• It is the smallest element of the Python program.
• All / any thing that we use in our program is a part of Token.
• It consist of 5 main elements in it. These are
Keywords
Punctuators
Identifiers
/ Separators
TOKENS
Operators Literals
• These are the reserved words whose meaning is already defined in
the language.
• They serve a specific task / purpose for which they are created.
• They cannot be used for any other purposes.
• Mostly in Python these are of lower case (small letters) and in
Default installation (CPython) when we type them they appear in
orange colour.
• Example of some Keywords are
• if
• else
• for
• False , None, True (only these three consist of capital letters in
them)
•These are the unique
names that we provide to
different programming
elements (such as variable,
functions, class etc) which
are created by us.
• The name should not start with digits.
• a1 1a
• It should not be a keyword
• abc if
• It should not contain any special symbols in it. (only special
symbol allowed is _ (underscore)
• Emp_salary ram@kumar
• The names are case – sensitive which means capital letters are
treated different from small letters
• Example if you a = 10
write A = 20
Python will not give any Error and treat them both separate. When you
write “a” you will get 10 and when you write “A” you will get 20
• It should not have blank spaces in it.
• abcxyz pqr abc
• The name can be of any length, but we should try to keep short and
meaningful names.
• Example for storing principle we can have p, pri, principle
Out of these 3 the pri is more favourable as name is short and meaning is
also
clear Some correct identifiers are Some invalid identifiers are
Myfile My.file
• The name can be combination of abc 12abc
• num1 num#
A–Z
_data data entry
• a–z emp_salary else
• 0–9
• and _ (underscore)
• These are the constant (fixed) values that do not change during the
program execution.
• It is the value that we assign to a variable. Eg a = 10
• Python consist of following Literals
• It is a collection of character type value which can consist of
A–Z a–z 0 – 9 or any special symbol
• It must be enclosed in ‘Single Quotes’ , “Double Quotes” or even
‘’’Triple Quotes’’’
• Without quotes python will not treat it as string
• Strings can be of two types:
• Single Line String
Needs to be created in a single line and is enclosed in single or double quotes
Example a=“Ram” nm=“Hello everyone”
• Multi Line String
Can cover multiple lines and is enclosed in triple quotes
Example a = ‘’’Ram address = ‘’’ 13 – B Delhi Road
Kumar ‘’’ Saharanpur ‘’’’
Note :
If you create single line string using ‘single’ or “Double” quotes and do
not end the string in same line them Python will give Error.
But you can continue single line string in more than one line by placing
\ (backslash) at the end of the line. Even then Python will treat it as a
single line string but will not give an Error.
• These are the non graphical characters that are
not displayed on the screen.
• They always start with a backslash ( \ ) symbol
and are followed by some predefined characters.
• They are called Escape Characters because they
are not displayed in the output.
• Their main purpose is to decorate the output on the
screen.
• They are always used with print() function as they are
used to modify the output.
Escape
Characte Name and Description
r• \n • New line : It is used to shift the matter present after it to
next line just like as we press the Enter Key from Keyboard
Task 2
Write a program to assign two complex numbers in two variables and
perform their addition and display the result.