Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet35/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   31   32   33   34   35   36   37   38   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

.title( )


Often, you’ll run into words that aren’t capitalized that should be usually names. The title method capitalizes all first letters in each word of a string. Try the following:

# using the title method to capitalize a string name = "john smith" print( name.title( ) )

Go ahead and run that cell. The output we get is a “John Smith” with capital letters on each word. This method is great for formatting names correctly.
Note Try using name.lower( ) and name.upper( ) and see what happens.

.replace( )


The replace method works like a find and replace tool. It takes in two values within its parenthesis, one that it searches for and the other that it replaces the searched value with:

# replacing an exclamation point with a period words = "Hello there!" print( words.replace( "!", "." ) )

Go ahead and run that cell. This will result in an output of “Hello there.”.
Note For the replace to be stored properly afterward, we would have to re- declare our words variable: words = words.replace(‘!’, ‘.’).

.find( )


The find method will search for any string we ask it to. In this example, we try to search for an entire word, but we could search for anything including a character or a full sentence:

# finding the starting index of our searched term s = "Look over that way" print( s.find("over") )

Go ahead and run that cell. You’ll notice that we got an output of 5. Find returns the starting index position of the match. If you count where the word “over” begins, the “o” is at index location 5. This is important when you want to access a specific index on a search. .strip( )
In cases where you want to get rid of a certain character on the left and right side of a string, you would use the strip method. By default, it will remove spaces. Let’s try running the following:

# removing white space with strip name = " john " print( name.strip( ) )

The output will produce “john” because we’ve removed all the spaces on the left and right side.
Note Try .lstrip( ) and .rstrip( ) and see what happens.

Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   31   32   33   34   35   36   37   38   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish