Class 11 Python Basic for beginners

 

Working with Python To write and run (execute) a Python program, we need to have a Python interpreter installed on our computer or we can use any online Python interpreter. The interpreter is also called Python shell. 


Here, the symbol >>> is called Python prompt, which indicates that the interpreter is ready to receive instructions. We can type commands or statements on this prompt for execution.


Execution Modes 

There are two ways to run a program using the Python interpreter: 

a) Interactive mode 

b) Script mode 

(A) Interactive Mode In the interactive mode, we can type a Python statement on the >>> prompt directly. As soon as we press enter, the interpreter executes the statement and displays the result(s),


Script Mode In the script mode, we can write a Python program in a file, save it and then use the interpreter to execute the program from the file. Such program files have a .py extension and they are also known as scripts.

To execute a Python program in script mode,


 

Python Keywords Keywords are reserved words. Each keyword has a specific meaning to the Python interpreter. As Python is case sensitive, keywords must be written exactly as given in Table


Identifiers In programming languages, identifiers are names used to identify a variable, function, or other entities in a program. The rules for naming an identifier in Python are as follows: 

• The name should begin with an uppercase or a lowercase alphabet or an underscore sign ( _ ). This may be followed by any combination of characters a-z, A-Z, 0-9 or underscore ( _ ). Thus, an identifier cannot start with a digit. 

• It can be of any length. (However, it is preferred to keep it short and meaningful). 

• It should not be a keyword or reserved word given in Table

• We cannot use special symbols like !, @, #, $, %, etc. in identifiers.


Variables Variable is an identifier whose value can change. For example variable age can have different value for different person. Variable name should be unique in a program.

Variables must always be assigned values before they are used in the program, otherwise it will lead to an error. Wherever a variable name occurs in the program, the interpreter replaces it with the value of that particular variable.



Question based on Above Knowledge

Write a Python program to find the sum of two numbers.

#To find the sum of two given numbers 

num1 = 10 

num2 = 20 

result = num1 + num2 

print(result) 

#print function in python displays the output 

Output: 30


Write a Python program to find the area of a rectangle given that its length is 10 units and breadth is 20 units.

To find the area of a rectangle 

length = 10 

breadth = 20 

area = length * breadth 

print(area) 

Output: 200



 Data Types 

Every value belongs to a specific data type in Python. Data type identifies the type of data which a variable can hold and the operations that can be performed on those data

>>> quantity = 10 

>>> type(quantity) 

>>> Price = -1921.9

 >>> type(price) 


Differnce between Expression and Statement

Statements:
  • Do something: Statements are instructions that perform an action, such as creating a variable, assigning a value, or controlling the flow of execution.
  • No value: Statements themselves don't produce a value.
  • Examples: x = 5if x > 10: print("Hello")for i in range(5): print(i)
Expressions:
  • Produce a value: Expressions combine values, variables, operators, and function calls to generate a single value.
  • Can be evaluated: Expressions can be evaluated to produce a result.
  • Examples: 5 + 3x * ylen("hello")my_function(10)
Key Differences:
  • Evaluation: Expressions are evaluated to produce a value, while statements are executed to perform an action.
  • Result: Expressions always return a value, while statements do not.
  • Use: Expressions can be used as part of statements, but statements cannot be used as part of expressions.


Operators 

An operator is used to perform specific mathematical or logical operation on values. The values that the operator works on are called operands. For example, in the expression 10 + num, the value 10, and the variable num are operands and the + (plus) sign is an operator.

we will continue operator in next article till then read this notes carefully and write in your notebook and ask your doubt with your class teacher .... you can also comment 


CLICK HERE SHORT NOTES OF PYTHON BASIC FOR BEGINNERS


Post a Comment

0 Comments