Variables, Data Types, Expressions, Operators

Reading

2. Variables, expressions and statements


Video

Learn to Program (0:00 - 19:20)

Code and Transcript

Most Important Concepts

  • A variable is a name for a location in memory.

  • Use a comma between a string literal and a string variable in print statements.

  • variable = input(prompt)

  • = is the assignment operator.

  • Many other languages require a variable be declared before being used.

  • Initialization is declaration and assignment at the same time.

  • In all languages, variables should be descriptive singular nouns.

  • In Python, the convention is to name variables in all lowercase with words separated by underscores. This is called snake_case.

  • Put comments in code to describe what code does.

  • Put a space before and after operators.


  • The input function returns a string.

  • To do math, strings must be converted to numbers using int or float like variable = int(input(prompt))

Sample Program

# Prof. Vanselow

# An integration of everything I have learned about programming

print("Welcome to my Integration Project!")


print("1. Calculate Area")

# side is a variable

# a variable is a name for a location in memory

side = int(input("Enter the length of the side of a square to get the area:"))

area = side * side

print(area)

# You could also do print(side * side)


print("Exiting.")