Class 11 CBSE - Python
Python is designed to understand the user’s responsibility, the protocol, and the ethical issues related to the field of computing.
Python in class 11 for cbse is very handy when it comes to practice on computers but for the beginers there might be some errors and problems such as exception. But it's always advisable to practice program on computer than writing it on paper because it cherishes your practical skills , knowledge and typing speed and you'll come to know new things and if you want to be a software developer someday then its a must call for you.
Python Fundamentals
Python Character Set
The character set is a list of characters and symbols which are allowed or valid in a particular language. Python has a well-defined character set.
It initially uses the traditional ASCII character set, but on the latest version, it also recognizes the Unicode character set also.
The UNICODE character set includes letter, digit, special symbols, escape sequences and white spaces.
- Letter :
It consist of uppercase letters (A-Z) & lowercase letters (a-z).
- Digits :
Numeric numbers like 0-9.
- Special character :
These include some special symbols used in Python language like #, %, *, {, etc.
- White Space :
These include blank spaces, tab space.
Token
Tokens are the smallest units of Python programming language.
Tokens in Python can be classified into five types: keywords, identifiers, literals, punctuators and operators.
Identifiers / Variables
Identifiers are building blocks of a program. The name of any variable, constant, function, or module is called as an identifier.
Variables are container that stores value that you can access or change. Variables are named after the word 'vary', which means we can modify their values during the execution of program.
Rules to declare identifiers :
- An identifier can be a combination of letters and numbers.
- An identifier must begin with an alphabet or underscore (_)
- As Python is case-sensitive, uppercase characters differ from lowercase characters, so the variable P is not the same as p.
- It is not permissible to use space and special symbols in identifiers
Let us see the example how variables are used :
Here, the variable name ‘a’ is assigned with the value 3.
This value is stored in a specific memory location with the name ‘a’ as show in the diagram
type() function :
This function is used to determine the type of data that a variable holds.
Keywords
Keywords are reserved words that convey special meaning to the compiler. They cannot be used as identifiers.
To check and display the list of keywords available in python, we have to write the following two statements:
import keyword
print(keyword.kWlist)
All the keywords available in python are in lowercase , except for False, None and True, which starts with a capital letter.
Literals
A fixed numeric or non-numeric value is called a literal. It can be defined as a number, text, or data that represents values to be stored in variables.
For Example : 2, -23.6, "abc", 'Independence'.
Operators
In a python programming language, these are special symbols which represents computations like addition, subtraction, less than (<), greater than (>), and many more operations.
Variable whose values are affected by these operators is referred to as an operand.
Aritmetic Operators
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc. For example,
a = 10 - 5 # 5
Here, - is an arithmetic operator that subtracts two values or variables.
a = 10 - 5 # 5
Relational Operators
Relational operators compare two values/variables and return a boolean result: True or False. For example,
a = 5
b =2
print (a > b) # True
Here, the > comparison operator is used to compare whether a is greater than b or not.
a = 5 b =2 print (a > b) # True
Logical Operators
Logical operators are used to check whether an expression is True or False. They are used in decision-making. For example,
a = 5
b = 6
print((a > 2) and (b >= 6)) # True
Here, and is the logical operator AND. Since both a > 2 and b >= 6 are True, the result is True.
a = 5 b = 6 print((a > 2) and (b >= 6)) # True