Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Python Studies

Rating
-
Sold
-
Pages
26
Uploaded on
31-12-2021
Written in
2021/2022

This will assist all those interested in coding and programming

Institution
Course

Content preview

Storing information using variables
Computers are useful for two purposes: storing information (also known as data) and performing
operations on stored data. While working with a programming language such as Python, data is
stored in variables. You can think of variables are containers for storing data. The data stored within
a variable is called its value. Creating variables in Python is pretty easy, as we've already seen in
the previous tutorial.




A variable is created using an assignment statement. It begins with the variable's name, followed by
the assignment operator = followed by the value to be stored within the variable. Note that the
assignment operator = is different from the equality comparison operator ==.

You can also assign values to multiple variables in a single statement by separating the variable
names and values with commas.




You can assign the same value to multiple variables by chaining multiple assignment operations
within a single statement.

,You can change the value stored within a variable by assigning a new value to it using another
assignment statement. Be careful while reassigning variables: when you assign a new value to the
variable, the old value is lost and no longer accessible.




The pattern var = var op something (where op is an arithmetic operator like +, -, *, /) is very
common, so Python provides a shorthand syntax for it.




Variable names can be short (a, x, y, etc.) or descriptive
( my_favorite_color, profit_margin, the_3_musketeers, etc.). However, you must follow
these rules while naming Python variables:

 A variable's name must start with a letter or the underscore character _. It cannot begin with
a number.
 A variable name can only contain lowercase (small) or uppercase (capital) letters, digits, or
underscores (a-z, A-Z, 0-9, and _).
 Variable names are case-sensitive, i.e., a_variable, A_Variable, and A_VARIABLE are all
different variables.

Here are some valid variable names:

, Let's try creating some variables with invalid names. Python prints a syntax error if your variable's
name is invalid.

Syntax: The syntax of a programming language refers to the rules that govern the structure of a valid
instruction or statement. If a statement does not follow these rules, Python stops execution and
informs you that there is a syntax error. You can think of syntax as the rules of grammar for a
programming language.




Built-in data types in Python
Any data or information stored within a Python variable has a type. You can view the type of data
stored within a variable using the type function.


Python has several built-in data types for storing different kinds of information in variables.
Following are some commonly used data types:

1. Integer
2. Float
3. Boolean
4. None
5. String
6. List

Written for

Course

Document information

Uploaded on
December 31, 2021
Number of pages
26
Written in
2021/2022
Type
Class notes
Professor(s)
Justus ngari
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
Mnyazi

Get to know the seller

Seller avatar
Mnyazi Freelancer
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
119
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions