Apuntes de Python (inglés)
Enviado por ANDRES STEVEN SIERRA • 3 de Julio de 2023 • Apuntes • 1.312 Palabras (6 Páginas) • 49 Visitas
Introducción a Pyhton
- It´s the language of choice* for many companies and a popular pick for personal projects. You can use it for automating tasks**, getting ahead in work with data analysis, machine learning, and much more. *Elección, **tareas/proyectos.
- No matter how complex a program is, it begins with a single line of code. This first line is usually a variable.
- Programs use variables to remember information. Like moving boxes, variables have content and names that tell us what´s inside.
Creating Variables
- To create a variable, we need to give it a name. Variable names need to be single words and, therefore, have no spaces. Tap the variable name city to get started.
- If we want a variable name with multiple words, we used snake case. Snake case means using _ to connect the additional words: home_city
- What do we use snake case for? To create variable names with multiple words.
- After creating and naming a variable, we use the = sign to store a value inside it, like with city = “Miami”
- What´s the value of this variable? name=”Karin”. The value is “Karin”.
- How do we know a value is a string*? It´s a Word between double quotes. *Cuerda/cadena.
- Lines of code are instructions for the computer to fllow. When we run code, we tell the computer to follow the instructions we put together*. *Reunimos.
- The order of the instructions matters because the computer follows the instructions line by line. Arrange these lines of code in the correct order, beginning with step_1, followed by step_2, and finally step_3.
- With the special instruction print( ), we tell the computer to display* a value in an area called the console, also known as the shell. *muestre print(“Hello, world!”): Hello, World!
- We can use the print( ) instruction as often* as we want. The computer displays every value on a line in the console. * Tan amenudo
- We can use print( ) to display variables like greeting*, too. *Como un saludo
Script.py
greeting = “Hello, World!”
print(greeting)
Output
Hello, World!
- When we display variables in the console, their values appear instead of their names. If we print name here, it´ll show its value.
Script.py
name = “Daenerys”
print(name)
Output
Daenerys
- How do we know “Hello, World!” is a string? It starts and ends with double quotes.
- What does this code display in the console? B-ball.
Script.py
sport = “B-ball”
print(sport)
Output
B-ball
- Display the value daily in the console
Script.py
frequency = “daily”
print(frequency)
Output
Daily
- Add the symbols to display this string value in the console.
Script.py
print(“Buzz”)
Output
Buzz
- Display the value of last_name.
Script.py
last_name = “Lightyear”
print(last_name)
Output
Lightyear
- Display the value of the job variable.
Script.py
job = “Sheriff”
print(job)
Output
Sheriff
Using Variables
- Variables are called variables because the values they store can change. We can update status by using = and giving it a new value.
Script.py
status = “Watching Netflix”
status = “Releaxing at the beach”
print(status)
Output
Relaxing at the beach
- We can update variables as often as we want. Try it yourself: change the value of status to “New data required”.
Script.py
status = “Incomplete”
status = “Complete”
print(status)
status = “New data required”
print(status)
Output
Complete
New data required
- We can also give variables the values of other variables. Here, we can give the new_status variable the value of default_option.
Script.py
default_option = “upload”
new_status = “download”
new_status = default_option
print(new_status)
Output
Upload
- When we update a variable, it forgets its previous value. Here, we can display the status variable twice and see how its value updates.
Script.py
status = “Playing football”
print(status)
status = “Walking the dog”
print(status)
Output
Playing football
Walking the dog
- Which of these lines of code updates the status variable? Status = “Working out”
- What does this code display in the console? Watching Netflix.
Script.py
status = “Watching Netflix”
print(status)
Output
Watching Netflix
- What´s wrong with this code? Nothing is wrong with this code.
Script.py
name = “Lori”
name = “Joe”
- What does this code display in the console? Median
Script.py
analysis = “Mean”
analysis = “Median”
print(analysis)
Output
Median
- Change the value in the temperature variable to “100 degrees”.
Script.py
temperature = “0 degrees”
temperature = “100 degrees”
print(temperature)
Output
100 degrees
- Update the status variable to “Writing code”.
Script.py
status = “Completing spreadsheet”
status = “Writing code”
print(status)
Output
Writing code
- Update the currency variable to “Dollar”.
Script.py
currency = “Euro”
currency = “Dollar”
print(currency)
Output
Dollar
- Change the value of the status variable to “Done”.
Script.py
status = “Unfinished”
status = “Done”
print(status)
Output
Done
Apuntes:
ADN = (“Inserte la secuencia: ”)
Uso de repleace: print(ADN.repleace(“Cambio”, “”))
Número de Adeninas: Num_A = ADN.count(“A”) #Cuenta cuantas “A” Hay en algo.
...