Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Python data types cheat sheet
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Booleans== * There are two booleans, <code>True</code> and <code>False</code>. * Use booleans to make decisions. ====Containment with 'in' and 'not in'==== >>> "H" in "Hello" True >>> "a" not in ["a", "b", "c"] False ====Equality==== * <code>==</code> tests for equality * <codE>!=</code> tests for inequality * <code><</code>, <code><=</code>, <code>></code>, and <code>>=</code> have the same meaning as in math class. >>> 0 == 0 True >>> 0 == 1 False "a" != "a" "a" != "A" ====Use with if/else blocks==== * When Python encounters the <code>if</code> keyword, it evaluates the expression following the keyword and before the colon. If that expression is <code>True</code>, Python executes the code in the indented code block under the if line. If that expression is <code>False</code>, Python skips over the code block. temperature = 32 if temperature > 60 and temperature < 75: print("It's nice and cozy in here!") else: print("Too extreme for me.") ====Types==== >>> type(True) <type 'bool'> >>> type(False) <type 'bool'>
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information