Questions #1


What are the types of strings in python?



Download 85,32 Kb.
bet3/24
Sana06.07.2022
Hajmi85,32 Kb.
#752107
1   2   3   4   5   6   7   8   9   ...   24
Bog'liq
interview en

What are the types of strings in python?
Depends on the version of Python. In the second branch, two types: single-byte strings and Unicode are represented by the str and unicode classes, respectively. Python 3 has one kind of string, str, which is Unicode. There are no single-byte strings, instead of them there is a bytes type, that is, a chain of bytes.
Is it possible to change a single character within a string?
No, strings are immutable. The replace, format, and concatenation operations return a new string.
How to concatenate a list of strings into one? How to split a string into a list of strings?
To join, you need the .join() string method. To split, the .split() method.
How to encode and decode strings?
Encode - translate Unicode into a byte string. Call the .encode() method on a unicode object.
Decode - recover Unicode from a string of bytes. Call the .decode() method on a str or bytes object (Python 2 and 3 respectively).
In both cases, explicitly pass the encoding, otherwise the one defined in the system by default will be used. Be prepared to catch UnicodeEncodeError, UnicodeDecodeError exceptions.
Comment out the expression 'ABC' == u'ABC'
Strings are compared by character codes. If both strings are typed in Latin, their codes are pairwise equal, and the resulting strings are also equal.
If at least one letter is typed in a Russian character, then the lines will not be equal. For example, the Russian letter A has a code different from the Latin letter A.
Remember that characters from the bottom of the ASCII table have the same codes in any encoding.

Lists, tuples, dictionaries, sets


How is a list different from a tuple?
At the language level, they differ in that you cannot add or remove an element to a tuple. There are no differences at the interpreter level. Both collections are represented by an array of pointers to a PyObject structure.
For a list, functions are defined that add a new element to such an array, remove an existing one, and merge two arrays into one. They are called by the list methods .append(), .pop(), .sort(), etc.

Download 85,32 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   24




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