Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Chapter -3 Python Fundamentals Part -1-2

The document covers Python fundamentals, including keywords, identifiers, literals, and operators. It explains character sets like ASCII and Unicode, the concept of tokens, and the different types of literals such as strings and numeric types. Additionally, it discusses escape characters, Boolean values, and collections in Python, along with tasks for practical application.

Uploaded by

deepanshu2550
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter -3 Python Fundamentals Part -1-2

The document covers Python fundamentals, including keywords, identifiers, literals, and operators. It explains character sets like ASCII and Unicode, the concept of tokens, and the different types of literals such as strings and numeric types. Additionally, it discusses escape characters, Boolean values, and collections in Python, along with tasks for practical application.

Uploaded by

deepanshu2550
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

JAIN HAPPY SCHOOL

CLASS 11( A+B)


SUBJECT-IP
CHAPTER-3
PYTHON FUNDAMENTAL
XI

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

• \t • Tab Spaces : It is used to give space equal to ½ inch or up to


8 characters just like we press Tab Key from Keyboard.
Escape
Characte Name and Description
r• \’ • Single Quotes: It is used to display ‘ ‘ quotation mark in the
output.

• \” • Double Quotes: It is used to display “ “ quotation mark in


the output.
Escape
Characte Name and Description
r• \\ • Backslash: It is used to display one \ backslash symbol
in the output.

• \b • Backspace: It is used to remove only one character from


the output just after which it is present. But will not work in
IDLE mode. It works in command line mode(Terminal).
Escape
Characte Name and Description
r• \a • alert: It is used to alert the user by producing a Beep sound
from the motherboard if the buzzer is connected to it. But
will not work in IDLE mode. It works in command line
mode(Terminal).

• \u • Unicode Characters: It is used to display 16 bit


Unicode character as output on the screen.
•These are the literals / values
that support only numeric type of
data.
•It further consist of 3 types in it
•int (Integer)
•float (Floating point value)
•complex (Complex number
of mathematics)
• It can store only numeric value in it. Eg : 72 , 84
• etc
The value can be positive ( + ) or negative ( - ). Eg : 34 , -23
• It should not have “ . “ decimal point in it. Eg : 75.32
• It should not have any comma separator in it. Eg : 13,500
• In Python integers can be represented in 3 ways
• Decimal Integer Literal Eg : 56 , 92
• Octal Integer Literal Eg : 045 , 027
• Hexadecimal Integer Literal Eg : 0X35A , 0XABC
• It can store only numeric value in it. Eg : 72.0 , 84.0
• etc
The value can be positive ( + ) or negative ( - ). Eg : 34.45 , -23.01
• It should have “ . “ decimal point in it. Eg : 75.32
• It should not have any comma separator in it. Eg : 13,500.99
• In Python float values can be represented in 2 ways
• Fractional form Eg : 3.14 , 0.058
• Exponent form Eg : 258.69E07 , 186.2E-5
(Also called as Scientific Notation)
• Advantage of float over integer are it can represent number
between integers Eg integer can be 1 , 2 but float can be 1.8, 1.26 etc
that is values between integers.
• Disadvantage is that they are slower in operations in comparison to int
• A complex number is made up of 2 parts
Real part and Imaginary part
• In mathematics it is written as real + imaginary i where i means −1
• In Python complex number is represented as real + imaginary j
• Here j symbol is used instead of i (as is used in mathematics) because
Python is used in electronics also and in electronics the symbol i
means current.
• Each part of complex number individually are float type of value.
• Example : c1 = 3.5 + 8.4j
• Python has two built – in attributes/variables called real and imag to
get the individual value of either real or imaginary part respectively.
• Example : print(c1.real) will give 3.5 and print(c1.imag) will give 8.4
• These are the sub types of integer literals.
• They consist of only two values
• True and False (both are Keyword in python)
• The True of Boolean is equivalent to 1 and
False is equivalent to 0.
• They are mostly used while we are working
with conditions to check something that it is
correct (True) or not (False).
• It is a keyword in Python
• It is used to tell the interpreter that the variable is
not having any value in it, which means it is not ready to
use.
• It will be used when you want to create a variable
but don’t have any value to assign it.
•• Any calculation
Example : amade with None will result in Error.
= None
b = a + 10 (Error)
a = 20
b = a + 10
• These are those types of values that can store
more than one value but with a single name.
• The 3 collections available in Python are:
• List
• Tuple
• Dictionary
• All of them can store multiple values in them and can
access either all or even individual value also.
• List and Tuple are called as Sequences in Python.
• Dictionaries are called as Mapping in Python.
Task 1
Write a program to demonstrate the use of all the Escape Characters
you have studied.

Task 2
Write a program to assign two complex numbers in two variables and
perform their addition and display the result.

You might also like