Venky Python
Venky Python
○ Python can be used for simple tasks such as plotting or for more complex tasks
like machine learning
Variables, Objects, and Classes
● A variable is a reference to a value stored in a computer’s memory.
● Variables can be sorted into a variety of categories (or data types)
such as numbers (int/float etc), Boolean values (true/false),
and sequences (strings, lists etc).
● An object is a collection of data from a computer’s memory that
can be manipulated.
○ Methods are the functions used to act on/alter an object’s data. They
describe what your object can “do.”
Variables, Objects, and Classes (cont.)
● A class is a collection of
objects who share the same
Instance #1
set of variables/methods. Color: Pink
Name: Polo
○ The definition of the class Instance #2
provides a blueprint for all the Color: Red
Name: Mini
objects within it (instances).
Instance #3
Color: Blue
○ Instances may share the same Name: Beetle
variables (color, size, shape, etc.),
but they do NOT share the same
values for each variable
(blue/red/pink, small/large,
square/circular etc.)
Basic Syntax Rules
● The name of your variable (myInt etc.) is placed on the left of the “=“ operator.
○ Most variable names are in camel case where the first word begins with a lowercase letter and any
subsequent words are capitalized
○ Variable names may also appear in snake case where all words are lowercase, with underscores between
words
● The assignment operator (“=“) sets the variable name equal to the memory location where your value is found.
● The value of your variable (“Hello, World”) is placed on the right of the “=“ operator.
○ The type of this value does NOT need to be stated but its format must abide by a given object type (as
shown).
myString = “Hello, World” myInt
=7
myFloat = 7.0
myList = [7, 8, 9] myBoolean =
true
Basic Syntax Rules
● Function Syntax
○ def...: indicates that you are defining a new function.
○ function() refers to the name of your function. By convention, this name is typically lowercase and represents a
verb/action.
○ a,b refers to parameters (values or variables) that can be used within the statements of your function’s definition
(......). If your function has no parameters, an empty parenthetical () is used.
○ The return statement is an optional statement that will return a value for your function to your original call.
○ If you wish, you can set your function call equal to a variable (myValue). The
value returned by the function will be assigned to your variable name.
myValue = function(1, 2)
Common Data Types and Operators
● A data type is a means of classifying a value and determining what
operations can be performed on it. All objects have a data type.
● Operators are symbols used carry out specific functions/computations.
Input/Output