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_10- This 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. for- This 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@1- This 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_1- This is a valid identifier as it conforms to the rules of making a valid identifier.
10. if- This 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. while- This 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.nd- This 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:
- Two types of strings supported in Python
- Single Line String
- Strings that are terminated in within a single line.
For example:
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 (" \ ")
in a Multiline format using backslash (" \ ")
- Using Triple quotation marks ("""):
- To create Multiline strings, we can also use three single/double quotes.
The Output will be:
For example: working on string ==>> "Hello, How are you?"
in a Multiline String format using Triple quotation marks (""")
in a Multiline String format using Triple quotation marks (""")
The Output will be :

Boys... You must have seen the outputs by both the methods
When we want the output to be exactly as we type, then we must use triple quotation marks ( """).

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.
#!/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
str='I LOVE COLUMBAS'
- What can you say about the string data type?
- Is there a difference between "Geeta" and 'Geeta'? Justify.
- Predict the output of the following:
- print("SCS"*5)
- print(("SCS"," ")*5)
- print("I"+"Love"+"Columbas")
- print("I","Love","Columbas")
- Suppose
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)
Good Morning Ma'am I am Joshua Walter of class 9-D.
ReplyDeleteGood morning ma'am this is Vincent Zacharias
ReplyDeleteHave fun Vincient we all will miss you
DeleteGood Morning Ma'am
ReplyDeleteKavyansh Bagotra 9D
Good morning Ma'am I am Kenn of9d
ReplyDeleteGood morning ma'am
ReplyDeleteMy name is Ryan Rahuel Valentine from class 9D
good morning mam aryan maheshwari here
ReplyDeleteGood morning mam I am Gunamay prasad of class 9 D
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood morning ma'am.
ReplyDeleteMy name is Ojas Khanna.
Ojas, did you use a computer or mobile phone while connecting in Google meet class?
DeleteMa'am I used an Ipad
DeleteGood 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.
ReplyDeleteOk maam
DeleteGood Morning Mam I am Derick Joseph of 9D
ReplyDeleteGood morning ma'am I am vansh bharti of class 9D
ReplyDeleteGood morning ma'am! This is Arjav Jain of class 9D
ReplyDeleteGood Morning Ma'am . My name is Advait Mohanty of class 9d.
ReplyDeleteGood morning sir I am samaksh of class 9-D
ReplyDeleteGood morning ma'am
ReplyDeleteI am soumil arora 9d
Good Morning ma'am .I am Gracious Benny of class 9-D
ReplyDeleteGood morning mam I am Kritik Kuraria
ReplyDeleteMam The 11th One Should Be Invalid as It has a special symbol
ReplyDeleteGood 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.
ReplyDeleteI had shared the answer to a question posted by Aryan. Please check on the previous blog, when time permits
ReplyDeleteALL THAT HAS BEEN SHARED ON THE BLOG IS TO BE NOTED.
ReplyDeleteTry and draw diagrams of the screen shots(or atleast note the statements and the output).
Nothing to be missed. Instructions have been clearly written
Good Morning ma'am
ReplyDeleteAaron John
Good morning ma'am.
ReplyDeleteSarhan Akhtar 9D.
Thanks Derick for pointing out the error. All to pls correct
ReplyDeleteif#-This is a invalid identifier as it is using # which is not a valid symbol in Python.
Good morning madam I'm Rishit Kumar
ReplyDeletePLS SHARE YOUR ROLL NO
DeletePls check the updated answer of Q11 and note the same.
ReplyDeleteGood morning Ma'am. I am Aryan Joseph Singh of 9D
ReplyDeleteAryan, You are very late my dear son
DeleteMa'am does python interpret single and double quotes similarly?
ReplyDeleteyou may either use single or double quotes in Python.
DeleteYes, they can replace each other
DeleteBut ma'am if we execute print(("SCS"," ")) on the IDLE window the output comes as
Delete('SCS', ' ') and in this the computer takes single quotes and prints the rest of the string
Good Morning Mam.
ReplyDeleteI am Abhishek Dial
9 D
Good morning Ma'am I am Kenn of9d
ReplyDeleteGood Morning ma'am.I am Gracious Benny of class 9-D
ReplyDeleteGood morning ma’am
ReplyDeleteMy name is Ryan Rahuel Valentine from class 9-D
Good morning maam i am samaksh goswami of class 9-D
ReplyDeleteGood morning ma'am. Samarth Raj 9D
ReplyDeleteMa'am where is the link of google meet?
ReplyDeleteGOOD MORNING MAM ARYAN MAHESHWARI HERE
ReplyDeleteGood morning mam I am Sandarbh of class 9-D
ReplyDeleteGood Morning Ma'am
ReplyDeleteThis is Joshua Walter of Class 9-D.
Good Morning ma'am
ReplyDeleteAaron John
Good morning ma'am .
ReplyDeleteMy name is Ojas Khanna
Good morning ma'am.
ReplyDeleteMy name is Sarhan Akhtar. (9D)
Good Morning Ma'am
ReplyDeleteThis is Shaun Roy of 9D
Good morning ma'am
ReplyDeleteMy name is soumil arora
Ma'am this is Vincent, wasn't there supposed to be google meet today?
ReplyDelete29 april?
Good morning ma'am
ReplyDeletethis is Arnav Trivedy
Good Morning Ma'am I'm Satwik Pruthi of class 9D
ReplyDelete