Introduction
Comparing to languages like C, Python's IF statement might be the simplest: There isn't even a single bracket in the statement.
The logical architecture is much simpler:
- ==, >=, <=, <, > comparison operators
- Manipulation of characters, numbers, and letters
- 'and' with 'or' multi-conditional comparison judgments
# and or judgement. (Can't use && and || operators in Python)
age_0 = 23
age_1 = 17
print(age_0 >= 21 and age_1 >= 21)
print(age_0 >= 21 or age_1 >= 21)
Output
False
True
'in' and 'not in' for list checking
topping = ['mushroom', 'pineapple']
if 'mushroom' in topping:
print('OK')
else:
print('No mushroom')
Output
OK
However, if you want to check whether an element is in an array in language like C (propose a number similar structure), this will be an extremely complicated operation to realize, because it's necessary to start from the data structure and determine the element type. Thus the judgment operation is a lot more complicated.
Multiple elif blocks
age = 8
if age < 3:
price = 0
elif age < 12:
price = 3
elif age < 18:
price = 5
else:
price = 10
print(price)
Output
3
Using the combination of list and 'if' operator to select
toppings = ['mushrooms', 'green peppers', 'onion', 'cheese', 'pineapple']
for topping in toppings:
if topping == 'green peppers':
print("No more green peppers.")
else:
print("OK, adding " + topping + ".")
print("Here is your pizza!")
Output
OK, adding mushrooms.
No more green peppers.
OK, adding onion.
OK, adding cheese.
OK, adding pineapple.
Here is your pizza!
Q: Does the list support value re-assignment operations in tuples (immutable after value assignment)?
A: The list is used internally in the tuple, although the tuple is immutable, but we can still mutate the list inside the tuple.
How to determine if the list is 'NULL'
From the perspective of the code, there are many ways to detect whether the list is 'NULL' or 'EMPTY', here are some examples such as the direct detection (if operation) and length detection (if len() is 0):
# Method 1: Using if else
topping = []
if topping:
print('Non-empty.')
else:
print('Empty.')
# Method2: Using len(LIST)
if len(topping) == 0:
print('Empty.')
Comments 30 comments
The comment is private
https://go88-tài-xỉu.net
https://8us.my
The comment is private
Hello88 la trong nhung thuong hieu ca cuoc truc tuyen hap dan duoc nhieu cuoc thu tin tuong va lua chon hien nay. Voi nguon goc tu chau A, Hello88 da thau hieu nhu cau, mong muon cua nguoi choi tu do co cho dung vung vang tren thi truong. De hieu sau hon ve cac san choi dinh dam nay cung diem qua noi dung thong qua bai viet duoi day. https://hello88-vn.com/
Cardiagtech is your go-to resource for all things automotive diagnostics. We offer top-quality car diagnostic tools, including car scan tools and car code readers, along with comprehensive car repair manuals .
nice
awesome
nice
The comment is private
The comment is private
Cookie Clicker Unblocked at Cookieclickerunblocked.co is an exciting and addictive game that’s perfect for passing the time. Whether you’re a casual player or someone who enjoys strategy and idle games, Cookie Clicker offers a delightful experience that will keep you hooked for hours. Website: https://cookieclickerunblocked.co/
Are you ready for a thrilling new challenge? Visit ovounblocked.me to experience the upgraded version of ovounblocked.me This latest update brings enhanced gameplay, smoother controls, and exciting new features, making it the ultimate destination for Ovo fans. Website: https://ovounblocked.me/
The comment is private
Chao mung ban den voi shidefc.com – diem den hang dau danh cho nhung ai dam me ca cuoc va giai tri truc tuyen!
The comment is private
The comment is private
The comment is private
The comment is private
Sao79 Club or Sao Win is a reputable card game portal with more than 500,000 downloads by 2024. Enjoy playing card games, Sic Bo, coin toss, fish shooting, lottery… Sao79 allows cross-platform transactions via Momo Pay, scanned bank codes, transfer, Zalo Pay, scratch cards… along with quick withdrawals to bank accounts, ATM cards. https://sao79.vip/
The comment is private
Are you ready to reel in the fun? The upgraded version of Tiny Fishing at TheTinyFishing.com takes your fishing experience to a whole new level. Dive into the exciting world of virtual fishing with enhanced features.
IWIN 68 – Trang chủ tải IWIN68 club cho APK/IOS, cổng game đổi thưởng trực tuyến chính thức tặng code 99K tại iwin68-club.net. IWIN68 cổng game bài đổi thưởng trực tuyến hàng đầu tại Châu Á, với nhiều trò chơi hấp dẫn bầu cua, xóc đĩa, tài xỉu, casino, thể thao,…
GEMWIN – GAME ĐẠI PHÚ QUÝ HOT NHẤT 2025 | ĐĂNG KÝ +100K, Chơi thả ga, nhận thưởng khủng, cơ hội trở thành tỷ phú tại gemwin.luxe !
link vào 8live – Nhà cái cá cược bóng đá uy tín Top 1 Châu Á. Link vào 8live mới nhất chính thức cập nhật 2025 tại 8live.cool, đăng ký mới +88k.
188BET là sòng bạc trực tuyến thuộc liên minh OKVIP. 188BET cung cấp đa dạng sản phẩm cá cược như: xổ số, bắn cá, đá gà, cá cược thể thao.. 188bet0.pro
The comment is private
吸うやつという女性おもちゃは、最近SNSで話題になっています。このアイテムは、クリトリスを吸引しながら刺激することで、気持ちよくなれるとされています。吸うやつは、女性の性的な快感を追求するための新しい選択肢として、今注目されています。
吸うやつ:https://www.beyourlover.co.jp/suction-goods
女性おもちゃ:https://www.beyourlover.co.jp/female-toys
You can use this platform to get an unforgettable experience of services.
This website is really amazing and gives me an unforgettable experience just like the one a use on daily basis https://capctemplategalaxy.com/
The comment is private