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.

tokens in python

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 :

python variables

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.

python type() function

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)


python keywords

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.

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.

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.

User Input




Python also allows to take user input for the desired value. The value which are inputted by the user are fetched and stored in the variable.

In python, there are two functions for getting users input, let's discuss each functions briefly:

input() :

In this function, the user can enter a value. This inputted value is then stored into variable.

For example:

>>name=input(“enter your name”)

Example :

python input() function

Output :

python user input

It does not matter whether the user enters an integer value, float value, or anything else. The user's input will be converted into a string. We can also check the type of data, inputted by the user using type() function.

eval() :

This function is an in-build function, used to evaluate the expression passed as a string. It takes the string as an argument, evaluating the string as one or more numbers and returning the numeric value.

python eval() function


User Defined Function




Functions are defined as a group of statements to perform specific tasks. Here, the definition of the function begins with the “def” keyword, which creates a function. The name of the function followed by the arguments passed in it. The arguments are enclosed between round brackets ().

Syntax :

python fuction syntax

python function example

Example :

python function example

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com