Class 11 AI Chapter - Python Topic - Token in Python - Arvindzeclass - NCERT Solutions

Post Top Ad

Sunday, October 20, 2024

Class 11 AI Chapter - Python Topic - Token in Python



Why Python Programming language is so important?

Python programming language is general purpose, object oriented. Python language was developed by Gudio Van Rossum in Feb 1991. It is not as much high level language as C, C++, Java

Features of Python:
1) It is a high level language.
2) It is free and open source language.
3)It is platform independent language.
4) It is interpreted language.
5) It is easy to use and understandable language.

What is token in Python programming language?

Python programs are made of tokens which is the smallest unit recognized by compiler and interpreter. They are consisting of keywords, identifiers, literals, operators, and punctuators.
Tokens in Python
1) Keywords: Reserve words which are used in Python are called Keywords. Each word has some meaning in programming.

as

Not

Continue

Try

for

While

None

False

assert

Import

Else

Break

Class

def

Try

Or

With

And

Finally

Not

elif


2) Identifiers: An identifier is defined to declare as variable, function, class, and object. Keywords can’t be used as identifiers. It can be declared by using character, number except underscore.

3) Literals: Literals are the values which are given in a program. It could be string literals, number literals, Boolean literals, and special literals.

4) Operators: Operators are the symbols which perform operations on values. There are different types of operators like maths operators, logical operators, and relation operators.

5) Punctuators: Punctuators are the symbols which add meaning in a code. There are many Punctuators like {}, (), ;, “” @, ?, : etc.


Program 1:
Write a program to find area of a rectangle where length = 25 cm and breadth = 2 cm.


What are the different data types used in Python?

Data types reserves memory in a system to run a program. Data operates with operators like maths operator or logical operators. Python also accept dynamic data type which is defined run time in a program.
data type in python
Data Type in Python

Data

Description

Example

Integer

stores whole numbers

B = 6

String

stores text enclosed in single or double quotes

Subject=’Hindi’

List

stores list of values of any data type separated with comma between square[]  

List=[34,12.5,”maths”,”Hindi”]

Tuple

stores list of values of any data type separated with comma between parentheses()

tuple=(34,12.5,”maths”,”Hindi”)

Set

stores unordered set of values of any data type with no duplicate between braces{}

set={34,12.5,”maths”,”Hindi”}

Dictionary

stores unordered set of comma separated key: value pairs between braces

Dic={1:”one”, 2:”two”}

Float

Stores numbers with fraction

B=23.6

Complex

Stores a number have real and imaginary part

No=a+bc

Boolean

It has two values true & false

Result=false


How values are accepted from user in Python?

In Python input() function is used to accept values from user. By default it accepts string values, we use conversion function to change data type.

Program 2:
Write a program to accept name, three subjects marks, and find total of it.
python program
Python Program




No comments:

Post a Comment

Post Top Ad