Home
Locate
CS 101
CS 496
Login
Tutors
Marks
About
Send
Close
Add comments:
(status displays here)
Got it!
This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.
nbsp; Note: This appears on each machine/browser from which this site is accessed.
Python: Comparison operator chaining
by RS
admin@ycp.powersoftwo.org
c
go
java
js
lua
py
vbs
rkt
scm
pro
1. Python: Comparison operator chaining
In CS 101, one learns that languages (such as C, Java, etc.) do not accept the following.
if (min1 < i1 <= max1) { ... }
Welcome to Python, where the language is adapted to the programmer instead of the programmer to the language. Here is the Python code.
list1 = [ i1 for i1 in range(10)] min1 = 4 max1 = 7 for i1 in list1: if (i1 > min1) and (i1 <= max1): print("{0:d}".format(i1)) print("") for i1 in list1: if min1 < i1 <= max1: print("{0:d}".format(i1))
Here is the output of the Python code.
5 6 7 5 6 7
2. End of page
3. Multiple choice questions for this page
4
questions omitted (login required)
by RS
admin@ycp.powersoftwo.org