Introduction to Variables
This module will help you get more familiarized with variables. For starters, please watch this video that gives you a background on variables.
Summary
Variables are ways to store information so that the computer can use it. Please note that the formula to declare a variable in python is as follows:
#FORMULA FOR VARIABLE DECLARATION
variable_name = variable_value
The three rules you should keep in mind when writing variables names are:
- You can’t have spaces between your variable name.
- You can’t have your variable name start with numbers.
- Variables are case-sensitive. When referencing your variables, write them exactly as you declared them.
Types of Variables
Python has a variety of variable types. For Intro To Code we will focus on three main variable types: strings, integers, and floats. For starters, please watch this video to familiarize yourself with variable types.
Summary
String variables are used to hold words, integer variables hold whole numbers, and float variables hold decimals.
When performing arithmetic to numeric variables (i.e. integers and floats), if there exists a float within the arithmetic, the result becomes of type float. Below are several types of arithmetic characters you can apply to integers and floats.
a * b #multiplication
a / b #division
a + b #addition
a - b #subtraction
a ^ b #exponentiation
To reassign a variable a different value, use the following formula:
#FORMULA FOR VARIABLE REASSIGNMENT
variable_name = new_value
Also there are three functions you can apply to variables that are going to come in handy for the Repl.it exercises: (1) type(var_name)
which allows you to see the type of the variable you are dealing with (2) int(var_name)
which allows you to convert something to an integer, and (3) str(var_name)
which allows you to convert something to a string. Below are the formulas for the functions:
#FORMULA FOR TYPE() FUNCTION
type(variable_name)
#FORMULA FOR INT() FUNCTION
int(variable_name)
#FORMULA FOR STR() FUNCTION
str(variable_name)
Variable Exercises
Please take look at this video walkthrough of the variable exercises module on Repl.it. Please feel free to follow along.
Variables More Practice and Resources
So now that you have completed the exercises, there exists another Repl.it module with additional practice problems. Those modules will go in more details about different variable problem solving strategies. Along with that, I have posted a video below for all those who wish to get a deeper understanding of variables in python. Good work thus far!
Extra Practice 1
Extra Practice 2
Extra Practice 3
Extra Practice 4
Variable Quiz
Using all that you have learned on variables, go ahead and try to the Variables Quiz on Repl.it! Best of luck! You got this!
Introducción A Variables
Este módulo lo ayudará a familiarizarse con las variables. Para empezar, mire este video que le da información básica sobre las variables.
Resumen
Las variables son formas de guardar información para que la computadora pueda usarla. Tenga en cuenta que la fórmula para declarar una variable en python es la siguiente:
#FORMULA PARA DECLARAR VARIABLE
nombre_variable = valor_variable
Las tres reglas que debe tener en cuenta al escribir nombres de variables son:
- No puede tener espacios entre su nombre de variable.
- No puede hacer que su nombre de variable comience con números.
- Las variables distinguen entre mayúsculas y minúsculas. Cuando haga referencia a sus variables, escríbalas exactamente como las declaró.
Tipos de Variables
Python tiene una variedad de variables. Para Intro To Code nos centraremos en tres tipos de variables principales: strings, integers y floats. Para empezar, mire este video para familiarizarse con los tipos variables.
Resumen
Las variables string se usan para contener palabras, las variables integers contienen números enteros y las variables floats contienen decimales.
Cuando se realiza aritmética a variables numéricas (es decir, integers y floats), si existe un float dentro de la aritmética, el resultado var ser de tipo float también. A continuación hay varios tipos de caracteres aritméticos que puede aplicar a integers y floats.
a * b #multiplicacion
a / b #division
a + b #addicion
a - b #sustracción
a ^ b #exponenciación
Para reasignar una variable a un valor diferente, use la siguiente fórmula:
#FORMULA PARA REASIGNAR VALOR DE VARIABLE
nombre_variable = valor_nuevo
También hay tres funciones que puede aplicar a las variables que serán útiles para los ejercicios de Repl.it: (1)type(nombre_var)
que le permite ver el tipo de la variable con la que está tratando (2) int(nombre_var)
que le permite convertir algo a un integer, y (3) str(nombre_var)
que le permite convertir algo a un string. A continuación se encuentran las fórmulas para las funciones:
#FORMULA PARA FUNCION TYPE()
type(nombre_variable)
#FORMULA PARA FUNCION INT()
int(nombre_variable)
#FORMULA PARA FUNCION STR()
str(nombre_variable)
Ejercisios de Variables
Por favor vea este video para ver la explicacion del modulo sobre los ejercicios de variables.
Variables Mas Practica y Recursos
Entonces, ahora que ha completado los ejercicios, existe otro módulo Repl.it con problemas de práctica adicionales. Esos módulos proporcionarán más detalles sobre diferentes estrategias de resolución de problemas variables. Junto con eso, he publicado un video a continuación para todos aquellos que desean obtener una comprensión más profunda de las variables en Python. Por favor ponga subtitulos en español! Buen trabajo hasta ahora!
Extra Practica 1
Extra Practica 2
Extra Practica 3
Extra Practica 4
Examen de Variables
Usando todo lo que has aprendido sobre variables, ¡continúa y prueba el examen de variables en Repl.it! ¡La mejor de las suertes! ¡Lo tienes!