python basics - xiaojianggis.github.io python data types.pdf · python basics xiao-jiang li, ph. d...
TRANSCRIPT
![Page 1: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/1.jpg)
Python basics
Xiao-jiang Li, Ph. D Candidate
Department of Geography, UCONN
![Page 2: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/2.jpg)
• Python is ideal for non-professional programmers
Easy to learn, and powerful.
• Python is Scripting language
Python interpreter can interpret (rather than compile)
and automate the execution of tasks
• Python is for automation
Work with software applications, Microsoft Office
• Python is for science
Numpy, Pandas, opencv…
Introduction of Python
![Page 3: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/3.jpg)
Python applications
![Page 4: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/4.jpg)
Python IDE
Python official website
![Page 5: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/5.jpg)
Python IDE
![Page 6: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/6.jpg)
Data types - Number
Integer
Number with no decimal part, 1, 2, 4
Float
Decimal number, like 1.10, 10.243
![Page 7: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/7.jpg)
Data types – number operations
Number operations
![Page 8: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/8.jpg)
Data types – number operations
Number operations of float and integer >>> a = 1
>>> c = 10.243
>>> print a+c
11.243
Conversion between float and integer >>> fa = float(a)
>>> print fa
1.0
>>> ic = int(c)
>>> print ic
10
![Page 9: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/9.jpg)
Data types – string
Strings are text, anything that is enclosed
by quotes.
Single or double quotes are fine but
consistency is needed for a given string.
![Page 10: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/10.jpg)
Data types – string
String operations
1. Print strings
Why? How to print ‘c:\desktop\notgood’
correctively
Add a ‘r’ before the string
![Page 11: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/11.jpg)
Data types – string
String operations
2. Connect two strings
3. The length of a string
![Page 12: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/12.jpg)
Data types – string
4. Other string operations
Lowercase, Uppercase, split …
>>> a = 'Apple'
>>> print a
Apple
>>> print a.lower()
apple
>>> print a.upper()
APPLE
>>> print a.split('l')
['App', 'e']
![Page 13: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/13.jpg)
Data types – string
5. Variable substitution in strings
The substitute is used to create a string dynamically.
%s is for string
%f is for float number
%d is for integer number
![Page 14: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/14.jpg)
Data structures
1. List
Stores numbers, strings, lists, dictionaries, etc.
Add a new element to the list
List sequences
![Page 15: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/15.jpg)
Data structures - list
2. Dictionary
Different with list, every element in a
dictionary has two attributes - key and value
J. Parent, 2013
![Page 16: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/16.jpg)
For loop
J. Parent, 2013
![Page 17: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/17.jpg)
For loop
For loop is used to do some repetitive
operations.
![Page 18: Python basics - xiaojianggis.github.io python Data types.pdf · Python basics Xiao-jiang Li, Ph. D Candidate Department of Geography, UCONN • Python is ideal for non-professional](https://reader034.vdocuments.site/reader034/viewer/2022042710/5f5ad7b22e60b418a3650e85/html5/thumbnails/18.jpg)