Python-String Literals(N)


Good Morning Boys

Welcome to the 5th session of the online classes for Python Programing.
--------------------------------------------------------------------------------------------------------------------------
Lets look at the solutions for the Exercise given in the last session.
1.      happy_10This is a valid identifier.
2.      For-This is a valid identifier because although "for" is a reserved word but because here it begins with capital f "F", it cannot be treated as a reserved word. User can use it as an identifier.
3.      forThis is an invalid identifier because it is a reserved word.
4.      10find-This is an invalid identifier because it is begins with a number.
5.      Count- This is a valid identifier as it conforms to the rules of making a valid identifier.
6.      Count 1-This is an invalid identifier because it is has a white space in between which is not allowed.
7.      cout@1This is an invalid identifier because it uses a special symbol "@" which is not allowed. Only underscore is allowed while creating a valid identifier.
8.      1count-This is an invalid identifier because it is begins with a number.
9.      Count_1This is a valid identifier as it conforms to the rules of making a valid identifier.
10.  ifThis is an invalid identifier because it is a reserved word.
11.  if#-This is an  invalid identifier as it is using # , a symbol that is invalid and is not available while creating identifiers.
12.  whileThis is an invalid identifier because it is a reserved word.
13.  while 2-This is an invalid identifier because it is has a white space in between which is not allowed.
14.  while_2-This is a valid identifier as it conforms to the rules of making a valid identifier.
15.  while.ndThis is an invalid identifier because it uses a special symbol "." which is not allowed. Only underscore is allowed while creating a valid identifier.
16.  while2-This is a valid identifier as it conforms to the rules of making a valid identifier.

I hope the concept is clear. Doubts if any, can be shared in the comments section.
______________________________________________________________________________

Lets start the topic for the day.- "Strings in Python"
========================================================================
By the end of the session, you will be able to 
  • Understand the string data type
  • definition and purpose of string data type
  • Ways to print strings
  • Apply the concatenation operator and repetition operators and  predict the output.
=======================================================================

    All of you are expected to copy the notes shared on the blog today.

    ====================================================================

    Python Strings

    • Strings in Python are identified as a contiguous set of characters represented in the quotation marks. 
    • Python allows for either pairs of single or double quotes. 
    • Example:
                  "Geeta",         'Pratham',      "1234",        '786'
    • Two types of strings supported in Python
      • Single Line String

        • Strings that are terminated in within a single line.
    For example: 
    Let's work on a SINGLE LINE STRING ==>>> "Hello, How are you?"                            
                            Output will be:
             
      • Multiline string
        • Piece of text that is spread along multiple lines
          (i.e. it covers more than one line)
        • There are two ways to create Multiline Strings:
          • Adding backslash (" \ ") at the end of each line.
    For example: working on string ==>> "Hello, How are you?" 
    in a Multiline format using backslash (" \ ")
          The Output will be:

          • Using Triple quotation marks ("""):
            • To create Multiline strings, we can also use three single/double quotes.
    For example: working on string ==>> "Hello, How are you?" 
    in a Multiline String format using Triple quotation marks (""")

    The Output will be :
                   
        Boys... You must have seen the outputs by both the methods


    • In First Method (i.e. by using backslash (" \ ") -- Even after writing the string in different lines we got the output on one single line as:
      Hello, How are you?
    • In Second Method (i.e. by using triple quotation marks ( """) -- We got the output same as we typed. i.e.:
      Hello,
      How
      are you?


    When we want the output to be exactly as we type, then we must use triple quotation marks ( """). 

    In addition to this, we can work on Strings using following characters... 
    •  The plus (+) sign is the string concatenation operator.
    •  The asterisk (*) is the repetition operator
    ---------------------------------------------------------------------------------------------------------------------------------For example −

    #!/usr/bin/python
    
    str = 'Hello World!'
    
    print str          # Prints complete string
    print str * 2      # Prints string two times
    print str + "TEST" # Prints concatenated string
    This will produce the following result −
    Hello World!
    Hello World!Hello World!
    Hello World!TEST
    EXERCISE
    1. What can you say about the string data type?
    2. Is there a difference between "Geeta" and 'Geeta'? Justify.
    3. Predict the output of the following:
      1. print("SCS"*5)
      2. print(("SCS"," ")*5)
      3. print("I"+"Love"+"Columbas")
      4. print("I","Love","Columbas")
    4. Suppose
    str='I LOVE COLUMBAS'
    Predict the output of the following:
    print str          # Prints complete string
    print str * 2      # Prints string two times
    print str + " MUSIC"


    You are requested to first try to predict the output based on your understanding and then try to check on the computer.


    God Bless You

    Computer Science Department
    (Middle School)
    Edited_Python-Strings.txt Displaying Edited_Python-Strings.txt.

    Comments

    1. Good Morning Ma'am I am Joshua Walter of class 9-D.

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

      ReplyDelete
    3. Good Morning Ma'am
      Kavyansh Bagotra 9D

      ReplyDelete
    4. Good morning ma'am
      My name is Ryan Rahuel Valentine from class 9D

      ReplyDelete
    5. good morning mam aryan maheshwari here

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

      ReplyDelete
    7. This comment has been removed by the author.

      ReplyDelete
    8. Good morning ma'am.
      My name is Ojas Khanna.

      ReplyDelete
      Replies
      1. Ojas, did you use a computer or mobile phone while connecting in Google meet class?

        Delete
    9. Good morning boys. I request all of you to make an effort to understand the sharing done today. I am waiting for doubts. We will have a Google meet session soon, where I will take us doubts pertaining to practical session. I request ALL to join as each lesson on the blog is important and paves way for the next session.

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

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

      ReplyDelete
    12. Good morning ma'am! This is Arjav Jain of class 9D

      ReplyDelete
    13. Good Morning Ma'am . My name is Advait Mohanty of class 9d.

      ReplyDelete
    14. Good morning sir I am samaksh of class 9-D

      ReplyDelete
    15. Good morning ma'am
      I am soumil arora 9d

      ReplyDelete
    16. Good Morning ma'am .I am Gracious Benny of class 9-D

      ReplyDelete
    17. Good morning mam I am Kritik Kuraria

      ReplyDelete
    18. Mam The 11th One Should Be Invalid as It has a special symbol

      ReplyDelete
    19. Good morning I am Satwik Pruthi of class 9D....Maam I request u to color the text which has to be written in our notebook in red or any specific color.

      ReplyDelete
    20. I had shared the answer to a question posted by Aryan. Please check on the previous blog, when time permits

      ReplyDelete
    21. ALL THAT HAS BEEN SHARED ON THE BLOG IS TO BE NOTED.
      Try and draw diagrams of the screen shots(or atleast note the statements and the output).

      Nothing to be missed. Instructions have been clearly written

      ReplyDelete
    22. Good morning ma'am.
      Sarhan Akhtar 9D.

      ReplyDelete
    23. Thanks Derick for pointing out the error. All to pls correct

      if#-This is a invalid identifier as it is using # which is not a valid symbol in Python.

      ReplyDelete
    24. Good morning madam I'm Rishit Kumar

      ReplyDelete
    25. Pls check the updated answer of Q11 and note the same.

      ReplyDelete
    26. Good morning Ma'am. I am Aryan Joseph Singh of 9D

      ReplyDelete
    27. Ma'am does python interpret single and double quotes similarly?

      ReplyDelete
      Replies
      1. you may either use single or double quotes in Python.

        Delete
      2. Yes, they can replace each other

        Delete
      3. But ma'am if we execute print(("SCS"," ")) on the IDLE window the output comes as
        ('SCS', ' ') and in this the computer takes single quotes and prints the rest of the string

        Delete
    28. Good Morning Mam.
      I am Abhishek Dial
      9 D

      ReplyDelete
    29. Good morning Ma'am I am Kenn of9d

      ReplyDelete
    30. Good Morning ma'am.I am Gracious Benny of class 9-D

      ReplyDelete
    31. Good morning ma’am
      My name is Ryan Rahuel Valentine from class 9-D

      ReplyDelete
    32. Good morning maam i am samaksh goswami of class 9-D

      ReplyDelete
    33. Good morning ma'am. Samarth Raj 9D

      ReplyDelete
    34. Ma'am where is the link of google meet?

      ReplyDelete
    35. GOOD MORNING MAM ARYAN MAHESHWARI HERE

      ReplyDelete
    36. Good morning mam I am Sandarbh of class 9-D

      ReplyDelete
    37. Good Morning Ma'am
      This is Joshua Walter of Class 9-D.

      ReplyDelete
    38. Good morning ma'am .
      My name is Ojas Khanna

      ReplyDelete
    39. Good morning ma'am.
      My name is Sarhan Akhtar. (9D)

      ReplyDelete
    40. Good Morning Ma'am
      This is Shaun Roy of 9D

      ReplyDelete
    41. Good morning ma'am
      My name is soumil arora

      ReplyDelete
    42. Ma'am this is Vincent, wasn't there supposed to be google meet today?
      29 april?

      ReplyDelete
    43. Good morning ma'am
      this is Arnav Trivedy

      ReplyDelete
    44. Good Morning Ma'am I'm Satwik Pruthi of class 9D

      ReplyDelete

    Post a Comment

    Popular posts from this blog

    Introduction

    Python-Modes

    Python-features