User Tools

Site Tools


python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
python [2020/01/19 22:45]
admin
python [2021/05/06 11:15] (current)
admin
Line 1: Line 1:
 +## Data Type
 +
 +^ Example ​                                      ^ Data Type  ^
 +| x = "Hello World" ​                            | str        |
 +| x = 20                                        | int        |
 +| x = 20.5                                      | float      |
 +| x = 1j                                        | complex ​   |
 +| x = ["​apple",​ "​banana",​ "​cherry"​] ​            | list       |
 +| x = ("​apple",​ "​banana",​ "​cherry"​) ​            | tuple      |
 +| x = range(6) ​                                 | range      |
 +| x = {"​name"​ : "​John",​ "​age"​ : 36}             | dict       |
 +| x = {"​apple",​ "​banana",​ "​cherry"​} ​            | set        |
 +| x = frozenset({"​apple",​ "​banana",​ "​cherry"​}) ​ | frozenset ​ |
 +| x = True                                      | bool       |
 +| x = b"​Hello" ​                                 | bytes      |
 +| x = bytearray(5) ​                             | bytearray ​ |
 +| x = memoryview(bytes(5)) ​                     |            |
 +
 +ref: https://​medium.com/​@shawnren527/​learn-about-python-3-data-types-numbers-and-strings-76c75a917c9b
 +
 ### Class ### Class
 ref:​https://​www.w3schools.com/​python/​python_classes.asp ref:​https://​www.w3schools.com/​python/​python_classes.asp
  
-### Create a list of objects from a class+## Create a list of objects from a class
 ```python ```python
    ​swatchList = []    ​swatchList = []
Line 13: Line 33:
 </​wrap>​ </​wrap>​
  
-### Format Variables+## Format Variables
 ```python ```python
    ​print('​%s %.2f' % ("hue =",​swSky1.hue))    ​print('​%s %.2f' % ("hue =",​swSky1.hue))
    ​print('​{0} {1:​.2f}'​.format("​hue =",​swSky1.hue))    ​print('​{0} {1:​.2f}'​.format("​hue =",​swSky1.hue))
    ​print("​hue =", format(swSky1.hue,'​.2f'​))    ​print("​hue =", format(swSky1.hue,'​.2f'​))
 +   # f:float, x:hex, s:string
 ``` ```
 The three lines above give the same result ````hue = 220.00````.\\ The three lines above give the same result ````hue = 220.00````.\\
Line 28: Line 49:
  
  
-### Plot (matplotlib)+## Plot (matplotlib)
 py37-matplotlib has the following notes:\\ py37-matplotlib has the following notes:\\
 The default backend is the interactive Mac OS X backend. Different backends can be specified using the The default backend is the interactive Mac OS X backend. Different backends can be specified using the
Line 41: Line 62:
 Note: ```markerfacecolor``` accept RGB, HEX and simple color text description:​ ```markerfacecolor=(r,​g,​b)```,​ ```markerfacecolor='#​333399'​```,​ ``` markerfacecolor='​green'​``` Note: ```markerfacecolor``` accept RGB, HEX and simple color text description:​ ```markerfacecolor=(r,​g,​b)```,​ ```markerfacecolor='#​333399'​```,​ ``` markerfacecolor='​green'​```
  
-### Common Error+### 3D plot: 
 +https://​jakevdp.github.io/​PythonDataScienceHandbook/​04.12-three-dimensional-plotting.html 
 + 
 +## Common Error
 ```python ```python
     File "​main.py",​ line 15     File "​main.py",​ line 15
python.1579445102.txt.gz · Last modified: 2020/01/19 22:45 by admin