Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1
Hi, welcome again. In the previous lecture
we were talking about numbers.
3
Specifically we looked at integers and
float data types so these are referred
5
to as data types in Python, so integers
and floats. In this lecture we're going
7
to look at strings. I already mentioned
strings in the previous lecture.
9
So a string is everything that goes
inside quotes. "Hi there". That is a string.
11
And of course strings can be stored in
variables and you can print those
13
variables, so we're using the interactive
shell now, but of course you can use a
15
part of script as we did previously.
So numbers were used to do math operations,
17
but strings, strings are used for
displaying information for the user.
19
So let's say you have a web application, and
you want to generate some text
21
dynamically on the web page, so you'd use
would use Python on the backend and
23
Python would send strings to the HTML
code and HTML would render the
25
code on the web page basically that's
the idea or if you want to create a
27
notepad, an editor with Python such as
Atom let's say, all these things you see
29
here so my program.py selection file,
so all this would be written as
31
strings inside Python and then you
display them on the interface using
33
various functions, for instance if you
want to display a string on the terminal
35
you'd use the print function. Now strings
have methods associated with them. What I
37
mean with methods is let me go ahead
and try out a method. Methods, for
39
methods you need to use the dot notation.
So you'd refer to the string which is
41
string c in our case actually
variable c, but the variable is holding
43
the strings so it's the same as doing
here dot, so let's do c dot, replace and
45
what I want to replace is e with i.
So I'm replacing, for string here I'm
47
replacing letter e with later i and what
that will do it will replace all
49
the letters, all the occurrences of this
letter in the string, so you'd ask where
51
can we see these method? Well that's
very easy actually. You can do dir and
53
then pass the string there, any string.
It could be c, it could be an empty string
55
or whatever and that will print out all
the available methods that you can use
57
with strings, so let's say c dot upper.
That will cover the strings to
59
upper case letters. Now if you want to
know what these methods are about you
61
could ask for help.
Just do help and then c, so the
63
string or just empty string dot
65
here replace method of the string
instance, so string is like the blueprint
67
that creates strings objects or you can
say the data type that represents texts.
69
Look here. Here is the syntax, so what you
do is, you use a string like we did.
71
So let's say here replace. Then you open
brackets. Here is the old item you want
73
to remove from the string and then the new
item we want to replace it with i and
75
then what you see here in square brackets,
that means this parameter is
77
optional so you can either pass it or
not and you know in the previous case we
79
didn't pass it so what Python did was
it replaced all the occurrences of the i
81
item but if you want to replace only the
first occurrence you do one there and
83
that will replace all the first i over
the first e with i. That's how it works
85
So strings, they support functions,
so print is a function. Here. And they support
87
methods like this one here and they also
support operators so you get "Here"
89
plus "There" and you get "HereThere" or you
can make it more readable like that so
91
an empty space is also a string and yeah
that's about strings for now and I'll
93
talk to you later.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.