Variables in Python

ComentariosTipos de datos

Variables are named containers for storing data values. In Python, you create a variable simply by assigning a value to a name – no need to declare the type beforehand.

Python is dynamically typed, meaning the type is determined at runtime and can change.

Creating Variables – Assignment

Use the equals sign = to assign a value.

Reassignment

You can change the value (and even type) of a variable anytime.

Naming Rules and Conventions

  • Must start with a letter or underscore (_)
  • Can contain letters, numbers, underscores
  • Case-sensitive (age and Age are different)
  • Use snake_case (lowercase with underscores) – Python convention
  • Avoid Python keywords (like print, if, for)

Multiple Assignment

Assign multiple variables in one line.

Swapping Variables

Quick Quiz

Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.

✨ Pregunta a Lara — tu compañera de estudio con IA

Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.


Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.

Sigue Tu Progreso 🚀

Aprende más fácilmente siguiendo tu progreso completamente gratis.