0% found this document useful (0 votes)
31 views

Lesson 10 - Variables: What Is A Variable?

This document discusses variables in Python. It defines a variable as a name associated with a value. Variables are assigned values using the assignment operator. It also discusses type conversion using the int() and float() functions to convert string inputs to numeric types. Identifiers are names used for program elements like variables, which can contain letters, digits, and underscores but must not begin with a digit. Operators are symbols that represent operations on operands, and there are unary and binary operators.

Uploaded by

raasiboi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lesson 10 - Variables: What Is A Variable?

This document discusses variables in Python. It defines a variable as a name associated with a value. Variables are assigned values using the assignment operator. It also discusses type conversion using the int() and float() functions to convert string inputs to numeric types. Identifiers are names used for program elements like variables, which can contain letters, digits, and underscores but must not begin with a digit. Operators are symbols that represent operations on operands, and there are unary and binary operators.

Uploaded by

raasiboi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lesson 10 - Variables

What is a Variable?
A variable is a name (identifier) that is associated with a value,
Num 10
Value vs. Name
Num = 5
VS.
X = num + 10
Variables are assigned values by assignment operator
X=5
So what does:
Num = num + 1

A note on input()
Input() returns a string!
Can I change a type in Python?

Type Conversion
Python provides a built-in type conversion functions
Int() and float()
Line = input(How many credits do you have?)
Num_credits = int(line)
Line = input(What is your GPA ?)
Gpa = float(line)
Line = input(How many credits?)
Num_credits = int(line)
If you enter 24, it is converted to the equivalent integer value, 24, before being
assigned to variable num_credits

Better yet:

Num_credits = int(input(How many credits? )

Identifiers
An identifier is a sequence of one or more chracters used to provide a name for a
given program element

What is an identifier?
Variable names
Line
Num_creidts
Gpa
Are each identifiers

What is an identifier?
Python is case sensitive, thus, line is different from line
Identifiers may contain letters and digits, but cannot begin with a digit.
Underscore character _ is also allowed to aid in the readability of long identifier
names

Operators
An operator is :
-

A symbol
Represents an operation
Performed on one or more operands

Types of operators
Unary operator operates on only one operand
Negation operator -12
Binary Operator operates on two operands
Addition a + b

You might also like