Python- Imp Terms
Good Morning dear Students
Welcome to the Computer Science session No. 4.
The Google meet ID for today's session is
The Google meet ID for today's session is
------------------------------------------------------------------------------------------------------------
You are expected
You are expected
- to note the content shared on this blog in your notebook.
- Home Work must be completed in your Computer Science Notebook.
----------------------------------------------------------------
By the end of this session, you will be able to
- Understand the two ways of executing Python program
- Write a simple Python program and execute the same.
- Familiarization with the basic components of a Python program
- tokens
- keywords
- identifiers
- Literals
____________________________________________________________________
Let us begin our session with the step by step explanation of the Practical question given as Home work -
In this Section, we will discuss the basic syntax of python by using which, we will run a simple program to print hello world on the console.
Python provides us the two ways to run a program:
- Using Interactive interpreter prompt
- Using a script file
Let's discuss each one of them in detail.
Method 1- Interactive interpreter prompt
- Python provides us the feature to execute the python statement one by one at the interactive prompt (as it uses an interpreter).
- It is preferable in the case where we are concerned about the output of each line of our python program.
- To open the interactive mode, open the terminal (or command prompt) and type python.
- It will open the following prompt where we can execute the python statement and check their impact on the console.
STEP-2
Let's run a python statement to print the traditional hello world on the console.
Python provides print() function to print some message on the console. We can pass the message as a string into this function. Consider the following image.
Here, we get the message "Hello World !" printed on the console.
Method 2- Using a script file:
- Interpreter prompt is good to run the individual statements of the code.
- However, we can not write the code every-time on the terminal.
- We need to write our code into a file which can be executed later.
- For this purpose,
- open an editor like notepad,
- create a file named first.py (python used .py extension) and
- write the following code in it.
To run this file named as first.py
- we press F5 or
- select
Let us see the steps to be followed:
STEP-1
STEP-2
Type the program, save the file using .py extension
STEP-3
Run the program.
Hence, we get our output as the message Hello World ! is printed on the console.
LET US LOOK AT SOME IMPORTANT TERMS RELATED TO PYTHON:-
- TOKENS-
- They are the smallest unit of a program.
- Characters are translated into a sequence of tokens.
- There are following tokens in Python:
- keywords
- literals
- identifiers
- operators
- punctuators
2. KEYWORDS-
- These are special words which are reserved by Python .
- They have specific meaning.
- We are not allowed to use keywords as variables in Python.
- Keywords are case-sensitive.
3. IDENTIFIERS-
- These are user-defined names to represent entities like variables, functions etc.
- We have rules to follow in order to create valid identifiers
RULES to follow while defining identifiers
1 1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _ Names like myClass, var_1 and print_this_to_screen, all are valid example.
2. An identifier cannot start with a digit. eg. 1variable is invalid, but variable1 is perfectly fine.
3. Keywords cannot be used as identifiers. eg. print cannot be used as an identifier.
4. We cannot use special symbols like !, @, #, $, % etc. in our identifier. The only symbol allowed is the underscore i.e. "_" e.g. var_1
5. An identifier can be of any length.
2. While, c = 10 is valid. Writing count = 10 would make more sense and it would be easier to figure out what it does even when you look at your code after a long gap.
3. Multiple words can be separated using an underscore, this_is_a_long_variable.
The following are some VALID identifiers:
MyFile
MYFILE
CHK
Z2t0Z29
DATE9_7_77
DS
FILE13
HJI3_JK
The following are some INVALID identifiers( along with the reason):
DATA-REC- contains special character – (hyphen) (other than A-Z,a-z,_(underscore))
29CLCT- starting with a digit
break - reserved word
My.file – contains special character dot (.)
4. LITERALS-
- Literals are the data that is given to a variable or a constant.A constant does not change while a variable gets its name from the fact that its value can change.
- The various types of literals are
- Strings
- Numeric
- Boolean
- Special
EXERCISE
Q1. Find whether the following Python identifiers are valid or not. Give reasons, if not valid:
1. happy_10
2. For
3. for
4. 10find
5. Count
6. Count 1
7. cout@1
8. 1count
9. Count_1
10. if
11. if#
12. while
13. while 2
14. while_2
15. while.nd
16. while2
That's all for today
Thank you Boys
Take Care & Stay Safe
1. happy_10
2. For
3. for
4. 10find
5. Count
6. Count 1
7. cout@1
8. 1count
9. Count_1
10. if
11. if#
12. while
13. while 2
14. while_2
15. while.nd
16. while2
That's all for today
Thank you Boys
Take Care & Stay Safe
Good morning ma'am I am vansh bharti of class 9D
ReplyDeleteGood morning ma'am .
ReplyDeleteMy name is Ojas Khanna. 9d
Good morning ma'am.
ReplyDeleteMy name is Sarhan Akhtar of class 9D.
Good morning mam. Samarth raj 9D
ReplyDeleteGood morning ma'am! Arjav Jain here
ReplyDeleteGood morning Ma'am. This is Advait Mohanty of class 9D.
ReplyDeleteGood morning ma'am I am Samaksh Goswami of class9-D
ReplyDeleteGood Morning ma'am
ReplyDeleteJason David 9-D
Good morning sir. I am Rishit Kumar
ReplyDeleteGood morning mam I am Kritik Kuraria
ReplyDeleteGood Morning ma'am
ReplyDeleteAaron John
Ma'am I can't hear you properly in the Google meet and I can't see the presentation also. It is all blurr
ReplyDeleteThere must be some technical issue at your end so. I dont think others had this problem
DeleteGood morning Ma'am. I am Aryan Joseph Singh of 9D
ReplyDeletegood morning mam aryan maheshwari here
ReplyDeleteGood Morning Mam.
ReplyDeleteI am Abhishek Dial
9 D
Good morning ma'am
ReplyDeleteThis is Arnav Trivedy
good morning ma'am this is Alvin johnson
ReplyDeleteGood Morning ma'am i am soumil arora
ReplyDeleteGood morning ma'am this is Vincent Zacharias.
ReplyDeleteSorry ma'am, but my question was if python can be used in User interface/ user experience?
ReplyDeleteThere are certain toolkits available for Python like Tkinter etc. which can be used to give you that experience
Deleteor is it a backend/ server side language?
DeleteThank you ma'am
DeleteGood Morning ma'am
ReplyDeleteKavyansh Bagotra 9D
Please give your attendance on the blog
ReplyDeleteGood morning Ma'am I am Kenn of9d
ReplyDeleteGood Morning Ma'am
ReplyDeleteJoshua Walter of Class 9-D.
Good Morning Mam I am Derick Joseph of 9D
ReplyDeletethis is karan kapoor
ReplyDelete9-D
Good morning I am Satwik Pruthi of class 9D
ReplyDeleteGood morning ma'am I am Waqar of class 9-D
ReplyDeleteGood morning mam I am Gunamay prasad of class 9 D
ReplyDeleteGood morning mam I am Gunamay prasad of class 9 D
ReplyDeleteGood Morning ma'am
ReplyDeleteI am Mohnish Kansal