0
Why in string with back slash is vsed with single quote .. It cant be some else ?
had a doudt
4 odpowiedzi
+ 2
I don't really understand, but try "
+ 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! """ )
+ 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'
- 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