Python/CheatSheet: Difference between revisions

From Wiki
No edit summary
Line 42: Line 42:
     if answer == '2':
     if answer == '2':
         break
         break
</pre>
</blockquote>
= Strings =
<blockquote>
<pre>
string = "Hello World"
string = 'Hello World'
string[4]        # = 'o'
</pre>
</blockquote>
== String functions ==
<blockquote>
<pre>
</pre>
</blockquote>
<blockquote>
<pre>
</pre>
</pre>
</blockquote>
</blockquote>
Line 76: Line 100:


== strftime & strptime format ==
== strftime & strptime format ==
<blockquote>
<pre>
</pre>
</blockquote>
<blockquote>
<pre>
</pre>
</blockquote>
<blockquote>
<pre>
</pre>
</blockquote>
<blockquote>
<pre>
</pre>
</blockquote>

Revision as of 11:40, 18 September 2017

Variables

Tuples

Lists

Dictionaries

Flow Control

If Then Else

if x < 0:
    print('Negative')
elif x == 0:
    print('Zero')
else:
    print('More')


For loops

for x in ['cat', 'dog', 'bird']:
    print (w)


While loops

while test:
    print (answer)


while True:
    print (answer)
    if answer == '2':
        break


Strings

string = "Hello World"
string = 'Hello World'

string[4]         # = 'o'

String functions




Functions

datetime

today()
now(timezoneinfo)
utcnow()
fromordinal(ordinal)
combine(date,time)
strptime(date,format)
fromtimestamp(timestamp)
utcfromtimestamp(timestamp)

time

replace()
utcoffset()
isoformat()
__str__()
dst()
tzname()
strftime(format)

strftime & strptime format