Python Tutorial For Beginners 3 | String Manipulation

Veröffentlicht am: 15 Juli 2020
auf dem Kanal: Pranav anand
176
10

As you can see, the first thing you learned was printing a simple sentence. This sentence was stored by Python as a string. However, instead of immediately printing strings out, we will explore the various things you can do to them.
#PythonTutorialForBeginners
#StringInPython
-----------------------------------------------------------------------------------------------------------------
first_name = 'ada'
last_name = "Lovelace"
print(first_name)
print(last_name)

#combining or concatenating string
full_name = first_name+" "+last_name
print(full_name)

#composing message using string variable
print("Hello,"+full_name+"!")

#title() method: begin with capital case
print(full_name.title())

#lower() method: converts string into lower case
print(full_name.lower())

#upper() method: converts string into upper case
print(full_name.upper())

#adding whitespace to string with tab "\t"
print("python")
print("\tPython")

#to add new line in string using "\n"
print("Language:\nPython\nC\nJava")

#you can also combine tab"\t" and "\n" in a single string
print("Language:\n\tPthon\n\tC\n\tJava")

#sytripping whitespace using strip()
language = ' Python '
print(language)
print(language.strip())

#removing extra space only from left side
print(language.lstrip())

#removing extra space only from right side
print(language.rstrip())

#accessing characters of a string
name= "kevin"
#display whole string
print(name)

#display first character of string
print(name[0])

#display third character
print(name[2])

#display the last character of string
print(name[-1])

#display second last character
print(name[-2])

#getting substring or slicing operation

str="PythonTutorial"
print(str)

#slicung 10th to last character
print("str[9:]: ",str[9:])

#slicing 3rd to 6th character
print("str[2:6]: ",str[2:6])

#slicing from start to 9th character
print("str[:9]: ",str[:9])

#slicing from 10th to second last character
print("str[9:-1]: ",str[9:-1])

#repetition of string-replication operator "*"
#repeating the string str by 3 times
print(str*3)

#check wether a string is present in another string or not
str1="welcome to python"
str2="welcome"
str3="xyz"

#str2 is in str1? TRUE
print(str2 in str1)

#str3 is in str1?FALSE
print(str3 in str1)

#str3 is not in str1? TRUE
print(str3 not in str1)


Auf dieser Seite können Sie das Online-Video Python Tutorial For Beginners 3 | String Manipulation mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Pranav anand 15 Juli 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 176 Mal angesehen und es wurde von 10 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!