python3 training basics - sjcode236/pyth GitHub Wiki
https://github.com/naftaliharris/tauthon (Py 2.8)
pythonclock.org
IDLE python editory , the simplest editor open a new window , write code , then run it
pudev --> its eclipse of Java
spyder --> new editor, it has annaconda built in it Anaconda distribution is available for WFFossware its better than pydev
pycharm is commercail -> community edition of pycharm is free https://www.jetbrains.com/pycharm
=========================================
Instructor Rob Gance email: [email protected]
Student Manual:
https://www.dropbox.com/s/d0ijr59fbodkxb5/IN1467%20Intensive%20Introduction%20to%20Python.pdf?dl=0
Instructor Slides:
https://www.dropbox.com/s/yehczglqt4mmjcm/IN1467_Intensive_Introduction_to_Python_instructor_slides.pdf?dl=0
Student files:
https://www.dropbox.com/s/nko3ugjkwcukmq0/IN1467_student_files.zip?dl=0
Student Manual:
https://cpcs-patching.wellsfargo.net/repositorymanager/MWS_Tooling/jim/PythonClass/IN1467_Intensive_Introduction_to_Python.compressed.pdf
Instructor Slides:
https://cpcs-patching.wellsfargo.net/repositorymanager/MWS_Tooling/jim/PythonClass/IN1467_Intensive_Introduction_to_Python_instructor_slides.pdf
Student Files:
https://cpcs-patching.wellsfargo.net/repositorymanager/MWS_Tooling/jim/PythonClass/IN1467_student_files.zip
===============================
pycharm
file -> settings -> Project: student_files -> Project Interpreter (here you can select the python interpretor)
tools -> Python console
https://regex101.com/tests https://txt2re.com/ [email protected]
Good url: https://automatetheboringstuff.com
Similar to our course, nothing advanced: https://python.swaroopch.com/stdlib.html
Another Python tutorial:
http://thepythonguru.com/
Long, time, recommended Python tutorial resource:
https://learnpythonthehardway.org/book/
Decebt slide-based tutorial:
https://stephensugden.com/crash_into_python/
Contains some intermediate topics (generators, decorators, ...):
http://www.learnpython.org/
http://www.diveintopython3.net/
import sys print(sys.version)
C:\ProgramData\Anaconda3\python.exe
C:\Users\dtc_train_wsnc_wec8\Documents\student_files\ch01_overview\04_sorting.py
=========================================== print(sys.version)
def my_func(greeting): print(greeting)
my_func('hello')
•Strings are immutable sequencesof Unicode characters
–Type: str
–Formal notation:my_str= str('Python is great!')
–Literal notation:my_str= 'Python is great!'
–May use single or double quotes (PEP-8 does not have a preference) -Triple quoted strings can span multiple lines. A common use is for documentation (called a docstring). my_str= 'Python's great fun' my_str= "Python is great fun" my_str= """Python is so much fun"""
•Strings are sequences and therefore support random access: my_str= 'Python is fun' print(my_str[0]) # 'P'
•Sequences may be sliced (sub-sequenced): slice = string[start : end : step] -tartval(included) -endval(excluded) print(my_str[0:9]) # 'Python is' print(my_str[:3]) # 'Pyt' print(my_str[3:]) # 'hon is fun' print(my_str[-1]) # 'n' Tip: copy = sequence[ : ] makes a shallow copy
•Strings may be concatenated (creates a new string):
my_str= 'Python is '
new_str= my_str+'fun'
•Long strings may be continued:
my_str= 'I just cannot seem
to finish this
darn string!'
•Strings (sequences) may be replicated:
'hello' * 3
hellohellohello
•join() ->Concatenates a list of strings using the specified separator string
nums= ['1','2', '3']
' '.join(nums)# 1 2 3
•split() ->Creates a list of strings based on a specifiedseparator string my_str= 'Python is great' my_list= my_str.split(' ')# Results: ['Python', 'is', 'great']
•replace() -> Returns a new stringwith all matching substrings replaced by the new one my_str.replace('is', 'is still')# yields: 'Python is still great'
*strip() -> Returns a new string with whitespace removed from each end new_str= ' Whitespace will be removed. '.strip() •find() -> Finds the index of the first occurrence of the substring my_str= 'Python is great' my_str.find('is')# returns 7 my_str.find('not')# returns -1 •str() -> String class constructoraccepts any object returns a string object s = str(55)# creates a string from the int s = str(3.14)# creates a string from the float •Use the type name as a function to perform conversions s1 = str(55)# '55' s2 = str(3.14)# '3.14' i1 = int('37')# 37 i2 = int(3.14)# 3 f1 = float(55)# 55.0 f2 = float('3.14')# 3.14 •If a conversion cannot be made, a ValueErroris raised: int('hello') ValueError: invalid literal for int() with base 10: 'hello'
===String format() •A preferredway to format data is to use the format() method of the string class s = 'It has been raining for {0}{1}and{0}{2}' new_str= s.format(40, 'days', 'nights') 'It has been raining for 40 days and 40 nights'
{ fieldname | index [!spec] [:format] }
s6 = '{lang} is over {0:0.2f} {date} old.'.format(20, date='years', lang='Python')
Python is over 20.00 years old.
# format() examples:
print('{0:>9}'.format('101.55')) # 101.55 (field-width of 9, > right aligned, remaining space fill substitute
character)
print('{0:->9}'.format('101.55')) # ---101.55
print('{0:-<9}'.format('101.55')) # 101.55--- ( < left aligned, remaining space fill substitute character)
print('{0:-^20}'.format('hello')) # -------hello--------(^ is center aligned,field-width 20,fill - remaining space)
•Additional string class methods include: capitalize() center(width, char) count(str) endswith(str) expandtabs() index() join(sequence) ljust(width, char) lower() isalnum() isalpha isdecimal() isdigit() isidentifier() islower() isnumeric() isprintable() isspace() istitle() isupper()