teaching:progappchim:notions_fondamentales

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
teaching:progappchim:notions_fondamentales [2021/01/11 11:51] – [Les listes] villersdteaching:progappchim:notions_fondamentales [2021/01/18 11:57] – [D'autres types] villersd
Ligne 91: Ligne 91:
  
 //Cf.// [[http://www.courspython.com/boucles.html|cet autre cours]] avec des illustrations et des exemples de code exécutable sur le site [[http://www.pythontutor.com|pythontutor]]. //Cf.// [[http://www.courspython.com/boucles.html|cet autre cours]] avec des illustrations et des exemples de code exécutable sur le site [[http://www.pythontutor.com|pythontutor]].
 +
 +FIXME : ajouter d'autres possibilités telles que présentées dans [[https://medium.com/analytics-vidhya/looping-techniques-in-python-3bbf907b8dfa|Looping Techniques in Python - Let’s learn about looping techniques using functions like enumerate, zip, sorted, reversed in python]] Indhumathy Chelliah; Medium, 30/07/2020
  
 ---- ----
Ligne 131: Ligne 133:
  
 Les caractères Unicode étant considérés comme abstraits dans Python 3, leur encodage (UTF-8, UTF-16,...) n'est à prendre en considération que si on utilise la méthode [[https://docs.python.org/3/library/stdtypes.html?highlight=encode#string-methods|.encode]] pour les convertir en bytes. Les caractères Unicode étant considérés comme abstraits dans Python 3, leur encodage (UTF-8, UTF-16,...) n'est à prendre en considération que si on utilise la méthode [[https://docs.python.org/3/library/stdtypes.html?highlight=encode#string-methods|.encode]] pour les convertir en bytes.
 +
 +=== Constantes ===
 +<code python>
 +import string # directive d'importation obligatoire pour ces exemples
 +
 +string.ascii_letters # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
 +string.ascii_lowercase # 'abcdefghijklmnopqrstuvwxyz'
 +string.ascii_uppercase # 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
 +string.digits # '0123456789'
 +
 +string.punctuation # '!”#$%&\’()*+,-./:;<=>?@[\\]^_`{|}~'
 +string.whitespace # ' \t\n\r\x0b\x0c'; \x0b is \v (vertical tab), \x0c is \f (form feed)
 +string.printable # = digits + ascii_letters + punctuation + whitespace
 +</code>
 +
 +=== Modifications, recherches, index, vérifications,... ===
 +<code python>
 +s.capitalize() # captilizes (first character becomes uppercase) the string
 +s.lower() # all characters become lowercase
 +s.casefold() # more rigorous lowercase (languages other than English are covered)
 +s.upper() # all characters become uppercase
 +
 +s.count(sub) # count occurences of substring sub in s
 +s.count(sub, start) # count occurences of substring sub starting from start position in string s
 +s.count(sub, start, end) # count occurences of substring sub from start to end — 1 position in string s
 +s.find(sub) # returns index of first occurence of substring sub in s, return -1 if not found
 +s.find(sub, start) # returns index of first occurence of substring sub starting from start position in string s, returns -1 if not found
 +s.find(sub, start, end) # returns index of first occurence of substring sub from start to end — 1 position in string s, return -1 if not found
 +s.index(sub) # returns index of first occurence of substring sub in s, raises error if not found
 +s.index(sub, start) # returns index of first occurence of substring sub starting from start position in string s, raises error if not found
 +s.index(sub, start, end) # returns index of first occurence of substring sub from start to end — 1 position in string s, raises error if not found
 +len(str) # returns length of string
 +
 +s.startswith(prefix) # checks if s starts with prefix
 +s.startswith(prefix, start) # checks if s starts with prefix starting from start position
 +s.startswith(prefix, start, end) # checks if s starts with prefix starting from start position until end — 1 position
 +s.endswith(suffix) # checks if s ends with suffix
 +s.endswith(suffix, start) # checks if s ends with suffix starting from start position
 +s.endswith(suffix, start, end) # checks if s ends with suffix starting from start position until end — 1 position
 +s.isalnum() # checks if string is alphanumeric
 +s.isalpha() # checks if string contains only alphabets
 +s.isnumeric() # checks if string contains only numbers
 +s.islower() # checks if all alphabets in string s are lowercase
 +s.isupper() # checks if all alphabets in string s are uppercase
 +s.isspace() # checks if s is a space character
 +
 +s.replace(old, new) # replaces substring old with substring new
 +s.replace(old, new, count) # replace substring old with substring new for count number of times starting from left side of string s
 +s.ljust(width) # puts width — len(s) spaces on the right side of string s
 +s.ljust(width, fillchar=c) # puts character c width — len(s) times on the right side of string s 
 +s.rjust(width) # puts width — len(s) spaces on the left side of string s
 +s.rjust(width, fillchar=c) # puts character c width — len(s) times on the left side of string s
 +s.strip() # all spaces gone left and right both sides of string s
 +s.lstrip() # all spaces gone on left side of string s 
 +s.rstrip() # all spaces gone on right side of string s
 +s.strip(k) # all substrings k gone left and right both sides of string s
 +s.lstrip(k) # all substrings k gone on left side of string s
 +s.rstrip(k) # all substrings k gone on right side of string s
 +s.split(‘,’) # splits the string by ‘,’; returns a list
 +s.split(‘::’) # splits the string by ‘::’; returns a list 
 +s.split(‘ ‘) # splits the string by ‘ ‘; returns a list
 +s.zfill(width) # adds width — len(s) zeros on the left side; if a +/- sign is there then zeros are added after it
 +
 +s.join(l) # joins a list or string l with substring s
 +</code>
  
 === Références === === Références ===
Ligne 267: Ligne 334:
  
  
-Consulter la [[https://docs.python.org/2/library/collections.html|documentation officielle]], et ces liens ([[http://pymbook.readthedocs.org/en/latest/collections.html|1]][[https://pymotw.com/2/collections/counter.html|2]], [[https://dzone.com/articles/python-201-whats-a-deque|3]][[https://towardsdatascience.com/the-most-undervalued-standard-python-library-14021632f692|4]])+  * Consulter la [[https://docs.python.org/2/library/collections.html|documentation officielle]], et ces liens 
 +    * [[http://pymbook.readthedocs.org/en/latest/collections.html]] 
 +    * [[https://pymotw.com/2/collections/counter.html] 
 +    * [[https://dzone.com/articles/python-201-whats-a-deque|Python 201: What’s a Deque?]] 
 +    * [[https://towardsdatascience.com/the-most-undervalued-standard-python-library-14021632f692|The Most Undervalued Standard Python Library Collections for data scientists]] Tyler Folkman, Medium, Oct 26, 2019 (video) 
 +    * [[https://levelup.gitconnected.com/introducing-high-performance-datatypes-in-python-with-the-collections-library-3d8c334827a5|Introducing high-performance datatypes in Python with the collections library]] George Seif, Medium, Oct 15, 2019
  
 Des types non intégrés par défaut dans Python peuvent facilement être implémentés, en utilisant les types répandus. C'est pas exemple le cas des [[https://fr.wikipedia.org/wiki/Arbre_enracin%C3%A9|arbres]] (informatique, théorie des graphes) : Des types non intégrés par défaut dans Python peuvent facilement être implémentés, en utilisant les types répandus. C'est pas exemple le cas des [[https://fr.wikipedia.org/wiki/Arbre_enracin%C3%A9|arbres]] (informatique, théorie des graphes) :
Ligne 570: Ligne 642:
   * Pour en savoir plus, consultez la page [[https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files]].   * Pour en savoir plus, consultez la page [[https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files]].
   * [[https://medium.com/better-programming/a-cheat-sheet-on-reading-and-writing-files-in-python-e78297adf413|A Cheat Sheet on Reading and Writing Files in Python - Quick reference on how to read and write files]] Yong Cui, Medium, 13/01/2020   * [[https://medium.com/better-programming/a-cheat-sheet-on-reading-and-writing-files-in-python-e78297adf413|A Cheat Sheet on Reading and Writing Files in Python - Quick reference on how to read and write files]] Yong Cui, Medium, 13/01/2020
 +  * [[https://medium.com/techtofreedom/file-handling-in-python-daee4586a64|File Handling in Python]] Yang Zhou, Medium, 25/04/2020
 +
  
  
  • teaching/progappchim/notions_fondamentales.txt
  • Dernière modification : 2023/05/03 08:39
  • de villersd