• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Dec 9th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # criando uma tupla vazia
2. >>> t_empty = ()
3. >>> t_empty
4. ()
5.
6. # criando uma tupla com valores
7. >>> t = (1, 2, 3, 'Fernando')
8. >>> t
9. (1, 2, 3, 'Fernando')
10.
11. # acessando os valores
12. >>> t[3]
13. 'Fernando'
14. >>> t[0]
15. 1
16.
17. # criando um 'mix' com tuplas
18. >>> t = (1, 2, 3, ['a', 'b'], {'id': 1, 'nome': 'Fernando'})
19. >>> t
20. (1, 2, 3, ['a', 'b'], {'id': 1, 'nome': 'Fernando'})
21. >>> t[4]
22. {'id': 1, 'nome': 'Fernando'}
23. >>> t[3[0]
24. 'a'
25.
26. # medindo o comprimento
27. >>> t = (1, 2, 3)
28. >>> len(t)
29. 3
30.
31. # fracionamento
32. >>> t = (1, 2, 3, ['a', 'b'], {'id': 1, 'nome': 'Fernando'})
33. >>> t[2:4]
34. (3, ['a', 'b'])
35.
36. # concatenaĆ§Ć£o
37. >>> t1 = (1, 2)
38. >>> t2 = (3, 4)
39. >>> t3 = t1+t2
40. >>> t3
41. (1, 2, 3, 4)
42.
43. # repetiĆ§Ć£o
44. >>>t3 * 3
45. (1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)
46.
47. # iteraĆ§Ć£o
48. >>> for i in t3: print i
49. 1
50. 2
51. 3
52. 4
53.
54. # participaĆ§Ć£o como membro
55. >>> 3 in t3
56. True
57. >>> 10 in t3
58. False
59.
60. # outra forma de criar uma tupla
61. >>> t = 1, 2, 3, 4
62. >>> t
63. (1, 2, 3, 4)
64. >>> type(t)
65. <type 'tuple'>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top