Difference between revisions of "Python programming"
m (corrected level of JSON) |
|||
Line 131: | Line 131: | ||
[https://docs.python.org/3/library/datetime.html datetime] module supplies classes for manipulating dates and times in both simple and complex ways. | [https://docs.python.org/3/library/datetime.html datetime] module supplies classes for manipulating dates and times in both simple and complex ways. | ||
== Working with [http://json.org JSON] in Python == | |||
[https://realpython.com/python-json/ Working With JSON Data in Python] by Lucas Lofaro | [https://realpython.com/python-json/ Working With JSON Data in Python] by Lucas Lofaro |
Revision as of 14:58, 30 March 2019
Python basics
Python IDE
In 2016 I started using PyCharm by JetBrains for Python IDE. JetBrains has a Community Edition version which is free.
Before PyCharm I used PyDev for my Python IDE. See My PyDev Notes section.
Escape sequences
Insert list or link to list of escape sequences
Type conversions
int() float()
Python string formatting
A nice collection of new and old Python format examples. I should really add some examples as this site has helped me out more than a few times. I like the examples and style used by the site.
Format Specification Mini-Language
time.strftime and use %f to get microseconds
Conditionals
Operator | Conditions when true |
---|---|
x == y | x and y have same value |
x != y | x and y don't have same value |
x < y | x value is less than y value |
x <= y | x value is less than or equal to y value |
x > y | x value is greater than y value |
x >= y | x value is greater than or equal to y value |
string methods (s1 and s2 are strings) | conditions when true |
s1.startswith(s2) | String s1 starts with s2 |
s1.endswith(s2) | String s1 ends with s2 |
s1.isalnum() | All characters in s1 are alphanumeric and there is >= 1 character |
s1.isalpha() | All characters in s1 are alphabetic and there is >= 1 character |
s1.isdigit() | All characters in s1 are digits and there is >= 1 character |
s1.islower() | All cased characters in s1 are lowercase and there is >= 1 cased character |
s.isupper() | All cased characters in s1 are uppercase and there is >= 1 cased character |
Lists, Tuples, Sets, Dicts
to do :: List operations you can perform on each...in a chart...
Sets // fill in later
Operation | Method Call | Returns |
Python operators
Loops
While loop
How to exit while loop using Enter key
while True: i = input("Enter text (or Enter to quit): ") if not i: break print("Your input:", i) print("While loop has exited")
For loop
How to cycle through elements viewing each one by pressing Enter key or any character to exit
for element_in_list in big_list: if not input("Press Enter to see next item or any other character to exit: "): print(element_in_list) else: break
Python datetime module
datetime module supplies classes for manipulating dates and times in both simple and complex ways.
Working with JSON in Python
Working With JSON Data in Python by Lucas Lofaro
Python Network Programming
My Python Network Programming Notes
Miscellaneous stuff
Difference Between Carriage Return, Line Feed and End of Line Characters