Différences
Ci-dessous, les différences entre deux révisions de la page.
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] villersd | teaching:progappchim:notions_fondamentales [2021/01/18 11:57] – [D'autres types] villersd | ||
---|---|---|---|
Ligne 91: | Ligne 91: | ||
//Cf.// [[http:// | //Cf.// [[http:// | ||
+ | |||
+ | FIXME : ajouter d' | ||
---- | ---- | ||
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:// | 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:// | ||
+ | |||
+ | === Constantes === | ||
+ | <code python> | ||
+ | import string # directive d' | ||
+ | |||
+ | string.ascii_letters # ' | ||
+ | string.ascii_lowercase # ' | ||
+ | string.ascii_uppercase # ' | ||
+ | string.digits # ' | ||
+ | |||
+ | string.punctuation # ' | ||
+ | string.whitespace # ' \t\n\r\x0b\x0c'; | ||
+ | string.printable # = digits + ascii_letters + punctuation + whitespace | ||
+ | </ | ||
+ | |||
+ | === Modifications, | ||
+ | <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, | ||
+ | s.count(sub, | ||
+ | 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, | ||
+ | s.index(sub, | ||
+ | len(str) # returns length of string | ||
+ | |||
+ | s.startswith(prefix) # checks if s starts with prefix | ||
+ | s.startswith(prefix, | ||
+ | s.startswith(prefix, | ||
+ | s.endswith(suffix) # checks if s ends with suffix | ||
+ | s.endswith(suffix, | ||
+ | s.endswith(suffix, | ||
+ | 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, | ||
+ | s.replace(old, | ||
+ | s.ljust(width) # puts width — len(s) spaces on the right side of string s | ||
+ | s.ljust(width, | ||
+ | s.rjust(width) # puts width — len(s) spaces on the left side of string s | ||
+ | s.rjust(width, | ||
+ | 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(‘, | ||
+ | s.split(‘:: | ||
+ | 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 | ||
+ | </ | ||
=== Références === | === Références === | ||
Ligne 267: | Ligne 334: | ||
- | Consulter la [[https:// | + | * Consulter la [[https:// |
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
Des types non intégrés par défaut dans Python peuvent facilement être implémentés, | Des types non intégrés par défaut dans Python peuvent facilement être implémentés, | ||
Ligne 570: | Ligne 642: | ||
* Pour en savoir plus, consultez la page [[https:// | * Pour en savoir plus, consultez la page [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | |||