Popular Posts

Friday, August 14, 2020

Python Beginner: Working with Strings and strings functions

 Hello, developer!


How are you? Hope you're fine to learn Python today. :)

Today, we will learn the handling way of strings. In this program, we will use strings variables and functions to convert strings as we want. A function is a block of codes that can be used by calling. Python includes several functions so developers can use functions by calling with parameters(data) and get return value(data). We will use internal functions(upper(), lower(), isupper(), islower(), len(), index(), replace()) to convert strings. I showed the purpose of each function as following.


Python Internal Functions for Strings

- string.upper(): Convert strings into all upper character strings(i.e.: Giraffe > GIRAFFE)

- string.lower(): Convert strings into all lower character strings(i.e.: Giraffe > giraffe)

- string.isupper(): Check the strings is all upper characters(i.e.: Giraffe > False)

- string.islower(): Check the strings is all lower characters(i.e.: Giraffe > False) 

- len(string): Length of strings(i.e.: Giraffe > 7(length of "Giraffe"))

- string.index(): Show the string position index(i.e.: index("G") > 0, index("e") > 6, starting from 0)

- string.replace("Giraffe", "Elephant"): Replace current strings into new strings(i.e.: Giraffe > Elephant)


I showed strings exercise code and execution result as below.

phrase = "Giraffe Academy"
print(phrase.lower())
print(phrase.upper())
print(phrase.isupper())
print(phrase.upper().isupper())
print(len(phrase))
print(phrase[0])
print(phrase[3])
print(phrase.index("G"))
print(phrase.index("Academy"))
# print(phrase.index("z")) : This code shows error because there is no "z" in phrase
print(phrase.replace("Giraffe", "Elephant"))
print(phrase + " is Cool")
print("Giraffe Academy")


Can you see the same result? Congratulations!

Alright, you learned string conversion functions and used strings variable in this program.


See you in the next post, developer! :)



1 comment:

  1. 1XBet
    Betting 1xbet korean in India. It can be great apr casino to find the most febcasino.com popular brands, especially หาเงินออนไลน์ ones that offer betting on sports such as football, tennis,  Rating: 1/10 · ‎Review by Riku VihreasaariWhere can I find 1xbet?Where can I find 1xbet betting?

    ReplyDelete

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...