-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtema_2.py
More file actions
113 lines (78 loc) · 2.33 KB
/
tema_2.py
File metadata and controls
113 lines (78 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 2. Tipos de datos
# camelCase o loweCamelcase
# UpperCamelCase
# kebab-case
# snake_case OK por python
# 1. Enteros
from cmath import sqrt
from decimal import Decimal
edad: int = 32 # decimal
base_binaria: int = 0b01
base_octal: int = 0o7
base_hexadecimal: int = 0xA
suma = 0o13 + 0o34
print('suma', suma)
print(5/2)
# Flotante
precio: float = 4.99
print(5/2.2)
valor: Decimal = Decimal(1024.99)
print('valor', valor)
# Strings - Cadenas
nombre: str = "Christhoval"
celular: str = '+507 64325621'
# apellido: str = input('Apellido: ')
apellido: str = 'Barba R'
# print('apellido= ', apellido)
print('-' * 100 )
print(nombre + ' ' + apellido)
print('%s %s = %i' % (nombre, apellido, edad))
print('{} {} = {}'.format(nombre, apellido, edad))
print('{name} {last_name} = 0x{age:x}'.format(name=nombre, last_name=apellido, age=edad))
print(f'{nombre} {apellido} = 0x{edad:x}')
print(f'La suma de {45} + {54} es igual a {45 + 54}')
plantilla: str = '''
I am the $master of my fate,
I am the $captain of my soul.
'''
print(plantilla)
from string import Template
_plantilla_ = Template(plantilla)
respuesta = _plantilla_.substitute(master='captain', captain='master')
print(Template(plantilla).substitute(master='captain', captain='master'))
usuario = 'Pepito Perez'
print('esPerez', 'perez' in usuario.lower())
print('noEsPerez', 'perez' not in 'Juan Diaz'.lower())
print(str(34567890 + 30))
print(usuario[0], usuario[7])
print(len(usuario))
print(usuario[len(usuario) - 1])
print(usuario[-1], usuario[-12])
print(usuario[0:6], usuario[7:12])
palindromo = 'reconocer'
print(palindromo, palindromo[::-1], palindromo == palindromo[::-1])
# metodos de cadenas
s = 'FoO BaR BAZ quX'
print('capitalize', s.capitalize())
print('lower', s.lower())
print('swapcase', s.swapcase())
print('title', s.title())
print('upper', s.upper())
print('count(B)', s.count('B'))
print('find(BAZ)', s.find('BAZ'))
print('isalnum', s.isalnum())
print('isalnum', 'asd124'.isalnum())
print('isalpha', s.isalpha())
print('isalpha', nombre.isalpha())
print('isdigit', '12343'.isdigit())
print('islower', nombre.islower())
print('isspace', s.isspace())
print('isspace', ' '.isspace())
print('center', s.center(50, '-'))
print('ljust', s.ljust(50, '-'))
print('rjust', s.rjust(50, '-'))
# Booleanos
cierto: bool = True
falso: bool = False
print(0 == False)
print(1 == True)