0

Why in string with back slash is vsed with single quote .. It cant be some else ?

had a doudt

18th Oct 2017, 12:53 PM
kesav naren
kesav naren - avatar
4 Respuestas
+ 2
I don't really understand, but try "
18th Oct 2017, 1:20 PM
NoxFly
NoxFly - avatar
+ 2
# Copy + run this code in CodePlayground # Try removing a \ and see what happens. # same types, messy print( "Text with \"double\" quotes") print( 'Text with \'single\' quotes' ) # Less messy print( "Text with 'single' ..." ) print( 'Text with "double"...' ) # Wnen you need it print( """ This "docstring's" got 'em both! """ )
18th Oct 2017, 1:26 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
The "\" character is the "escape" character. If you had a string in single quotes ( ' <- these): string = 'hi' and wanted to add some single quotes in there, for example: string = 'hi, I am Amy's friend' ^ then Python would be confused as to where the string ends, assuming it ends at the ' in "Amy's" instead of at the one after friend. This is where the "\" comes in: string = 'hi, I am Amy\'s friend'
18th Oct 2017, 2:26 PM
LunarCoffee
LunarCoffee - avatar
- 1
read in-code and also o/p comments it covers all string manupulation methods includinh ur doubts... @ kesav https://code.sololearn.com/cnK7GbSZLglD/?ref=app
18th Oct 2017, 1:58 PM
sayan chandra
sayan chandra - avatar