5. Python - Strings

 Strings:

// Strings are arrays of characters, except strings are immutable

"Print's Dog"


Escaping signs:

"Print\'s Dog"


The table below summarizes some important uses of the backslash character.

What you type...What you getexampleprint(example)
\'''What\'s up?'What's up?
\"""That's \"cool\""That's "cool"
\\\"Look, a mountain: /\\"Look, a mountain: /\
\n
"1\n2 3"1
2 3


Auto new lines:

print(""" HELLO


""")


Print and End:

// print ends with auto newline unless specify end=

print("TEST", end = "HELLO")


String Methods:

string.upper() // uppercase

string.lower() // lowercase

string.index("substring") // searches for the index where substring starts

string.startswith()

string.endswith()

string.split('optionalseparator') // splits a string into a array of words using whitespace as separator

stringseparator.join("HELLO","BANANA") // joins HELLO with BANANA with separator in middle


String convert from int/float:

str(5)


Formatting strings:

"Today is {}".format(month) // brackets is placeholder for variable

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort