Python- Imp Terms


Good Morning dear Students
Welcome to the Computer Science session No. 4. 

The Google meet ID for today's session is

Meeting ID
------------------------------------------------------------------------------------------------------------
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 -

First Python Program:
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-1


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.

  1. Print ("hello world"); #here, we have used print() function to print the message on the console.   
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:-
  1. 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.



    Things to Remember:
    1. Python is a case-sensitive language. This means, Variable and variable are not the same. Always name identifiers that make sense.

    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

    Comments

    1. Good morning ma'am I am vansh bharti of class 9D

      ReplyDelete
    2. Good morning ma'am .
      My name is Ojas Khanna. 9d

      ReplyDelete
    3. Good morning ma'am.
      My name is Sarhan Akhtar of class 9D.

      ReplyDelete
    4. Good morning mam. Samarth raj 9D

      ReplyDelete
    5. Good morning ma'am! Arjav Jain here

      ReplyDelete
    6. Good morning Ma'am. This is Advait Mohanty of class 9D.

      ReplyDelete
    7. Good morning ma'am I am Samaksh Goswami of class9-D

      ReplyDelete
    8. Good Morning ma'am
      Jason David 9-D

      ReplyDelete
    9. Good morning sir. I am Rishit Kumar

      ReplyDelete
    10. Good morning mam I am Kritik Kuraria

      ReplyDelete
    11. Ma'am I can't hear you properly in the Google meet and I can't see the presentation also. It is all blurr

      ReplyDelete
      Replies
      1. There must be some technical issue at your end so. I dont think others had this problem

        Delete
    12. Good morning Ma'am. I am Aryan Joseph Singh of 9D

      ReplyDelete
    13. good morning mam aryan maheshwari here

      ReplyDelete
    14. Good Morning Mam.
      I am Abhishek Dial
      9 D

      ReplyDelete
    15. Good morning ma'am
      This is Arnav Trivedy

      ReplyDelete
    16. good morning ma'am this is Alvin johnson

      ReplyDelete
    17. Good Morning ma'am i am soumil arora

      ReplyDelete
    18. Good morning ma'am this is Vincent Zacharias.

      ReplyDelete
    19. Sorry ma'am, but my question was if python can be used in User interface/ user experience?

      ReplyDelete
      Replies
      1. There are certain toolkits available for Python like Tkinter etc. which can be used to give you that experience

        Delete
      2. or is it a backend/ server side language?

        Delete
    20. Good Morning ma'am
      Kavyansh Bagotra 9D

      ReplyDelete
    21. Please give your attendance on the blog

      ReplyDelete
    22. Good Morning Ma'am
      Joshua Walter of Class 9-D.

      ReplyDelete
    23. Good Morning Mam I am Derick Joseph of 9D

      ReplyDelete
    24. Good morning I am Satwik Pruthi of class 9D

      ReplyDelete
    25. Good morning ma'am I am Waqar of class 9-D

      ReplyDelete
    26. Good morning mam I am Gunamay prasad of class 9 D

      ReplyDelete
    27. Good morning mam I am Gunamay prasad of class 9 D

      ReplyDelete
    28. Good Morning ma'am
      I am Mohnish Kansal

      ReplyDelete

    Post a Comment

    Popular posts from this blog

    Introduction

    Python-Modes

    Python-features