pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pythonitalia/python-abc/blob/master/docs/Pyllole/55_Type_Tuple.md

sets/global-0bd78641c0a1f3e0.css" /> python-abc/docs/Pyllole/55_Type_Tuple.md at master · pythonitalia/python-abc · GitHub
Skip to content

Latest commit

 

History

History
85 lines (67 loc) · 1.49 KB

File metadata and controls

85 lines (67 loc) · 1.49 KB

Tipi: Tuple

Prima di studiare le tuple assicurati di conoscere le liste.

Le tuple sono come le liste ma immutabili.

>>> tup = (1, 2, 3)                                    
>>> tup
(1, 2, 3)
>>> type(tup)
<class 'tuple'>

Puoi fare tutte queste operazione, che fai con le liste, anche sulle tuple

>>> len(tup)                                           
3
>>> tup + (4, 5, 6)
(1, 2, 3, 4, 5, 6)
>>> tup[:2]
(1, 2)
>>> 2 in tup
True

Puoi scompattare le tuple (o liste) in variabili

>>> a, b, c = (1, 2, 3)                                
>>> a
1
>>> b
2
>>> c
3

puoi anche omettere le parentesi

>>> d, e, f = 4, 5, 6                                  
4
>>> e
5
>>> f
6

Le tuple sono create di default se non usi le parentesi

>>> g = 4, 5, 6                                        
>>> g
(4, 5, 6)
>>> type(g)
<class 'tuple'>

Guarda come è facile scambiare due valori

>>> e, d = d, e                                        
>>> e
4
>>> d
5

Importante: Si noti che una tupla di lunghezza uno deve avere una virgola dopo l'ultimo elemento ma tuple di altre lunghezze, anche zero, no.

>>> type((1))
<class 'int'>
>>> type((1,))
<class 'tuple'>
>>> type(())
<class 'tuple'>

This content is a derivative of "Learn X in Y minutes" by adambard, used under a CC BY-SA 3.0 license.

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy