Differences

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

Link to this comparison view

ic:resurse:python [2021/10/03 14:13]
razvan.smadu
ic:resurse:python [2023/10/02 00:10] (current)
razvan.smadu [Python3 Crash Course]
Line 18: Line 18:
 <​note>​ Recomandăm să aveți instalat Python 3, întrucât Python 2 nu mai are [[https://​www.python.org/​doc/​sunset-python-2/​|suport oficial]] de la 1 ianuare 2020, iar sintaxa între cele două versiuni diferă. </​note>​ <​note>​ Recomandăm să aveți instalat Python 3, întrucât Python 2 nu mai are [[https://​www.python.org/​doc/​sunset-python-2/​|suport oficial]] de la 1 ianuare 2020, iar sintaxa între cele două versiuni diferă. </​note>​
  
-În cazul în care nu aveți Python 3 instalat, puteți folosi ​pachet ​managerul (ex. apt, yum, pip), [[https://​docs.conda.io/​en/​latest/​miniconda.html|conda]],​ sau puteți descărca direct de pe [[https://​www.python.org/​downloads/​|site-ul oficial]].+În cazul în care nu aveți Python 3 instalat, puteți folosi managerul ​de pachete ​(ex. apt, yum), [[https://​docs.conda.io/​en/​latest/​miniconda.html|conda]],​ sau puteți descărca direct de pe [[https://​www.python.org/​downloads/​|site-ul oficial]].
  
 În Windows, puteți descărca de pe [[https://​www.microsoft.com/​en-us/​p/​python-39/​9p7qfqmjrfp7|Microsoft Store]], puteți folosi [[https://​docs.conda.io/​en/​latest/​miniconda.html|conda]],​ sau puteți descărca direct de pe [[https://​www.python.org/​downloads/​|site-ul oficial]]. În Windows, puteți descărca de pe [[https://​www.microsoft.com/​en-us/​p/​python-39/​9p7qfqmjrfp7|Microsoft Store]], puteți folosi [[https://​docs.conda.io/​en/​latest/​miniconda.html|conda]],​ sau puteți descărca direct de pe [[https://​www.python.org/​downloads/​|site-ul oficial]].
Line 257: Line 257:
 r1 = random.random() r1 = random.random()
 </​code>​ </​code>​
 +
 +=== Type Hints ===
 +
 +Python este un limbaj tipat dinamic. Pentru a ușura întelegerea codului, putem folosi type hints care reprezintă adnotări asupra tipurilor de date. Acestea nu sunt forțate la runtime, fiind responsabilitatea programatorului să se asigure că tipurile nu induc în eroare. Detalii legate de type hints se pot găsi în [[https://​docs.python.org/​3/​library/​typing.html|documentație]],​ [[https://​peps.python.org/​pep-0484/​|PEP 484]] și [[https://​peps.python.org/​pep-0483/​|PEP 483]].
 +
 +Exemple:
 +<code python>
 +from typing import Dict, List, Sequence, Tuple, TypeVar
 +
 +my_string: str = "hello world" ​ # A variable storing a string
 +my_number: int = 10  # A variable storing an integer
 +
 +# A function returning nothing
 +def main() -> None:
 +    return ​ # Returns nothing (i.e., None)
 +
 +# A function that takes some arguments, and returns a tuple
 +def compute(a: int, b: float, c: List[str]) -> Tuple[int, float]:
 +    return a, b  # This is a tuple of `a` and `b`
 +
 +T = TypeVar('​T'​) ​ # Declare type variable
 +
 +def first(l: Sequence[T]) -> T:  # A generic function
 +    return l[0]
 +
 +# Type alias
 +MyCustomType = Dict[str, List[Tuple[int,​ int]]]
 +</​code>​
 +
  
 ==== Referințe ==== ==== Referințe ====
ic/resurse/python.1633259611.txt.gz · Last modified: 2021/10/03 14:13 by razvan.smadu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0