Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet30/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   26   27   28   29   30   31   32   33   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Membership Operators
Although not commonly used, however, they are used in sequences like strings, lists, and tuples.
In Python, we have two membership operators – “not in” and “in.” The operators give you the
result depending on the variable available in the string or sequence you specified. Let us see how
you can use them in a program.
number1 = 15
number2 =56
new_list = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ];
if ( number1 in new_list ):
print("number1 is available in our given list.")
else:
print("number1 is unavailable in our given list")
if ( number2 not in new_list ):
print("Number2 is not available in our given list.")
else:
print("number2 is available in our given list")
Let see how the program runs line by line. In the first and second lines, we declare two variables
and assign values for them. In the third line, we created a list “new_list” before using an if-else
statement to test the membership operator on our list. we check if number1 is available in our
list; depending on the number, it prints the expression based on the condition it fulfills. It does
the same for number2 before printing out the desired result. In our program above, our output
will be:
number1 is available in our given list.
number2 is not available in our given list.
Summary
Operators are important functions used in programming languages to perform various operations
on operands. However, in Python, we use operations such as:


Arithmetic  operators  to  perform  operations  on  operands;  these  operators  include
addition, subtraction, multiplication, division, exponent, and modulus. Python also
uses the call functions, declare variable $ calculate, and eval function.
Comparison operators used to compare operands on both sides before determining
the relationship between them
Assignment  operators  to  assign  values  to  variables;  we  also  have  a  compound
assignment operator, which allow you to assign the result of an operand
Logical  operators,  which  include  NOT,  OR,  and  AND.  They  are  used  to  return
either true or false, depending on the condition set.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   126




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