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
Summary

Summary Python variables

Rating
-
Sold
-
Pages
7
Uploaded on
02-12-2023
Written in
2023/2024

Python variables tutorial for beginners in English

Institution
Course

Content preview

#4 Python Tutorial for Beginners | Variables in Python
Telusko


Welcome back, aliens!

My name is Devin 20 and in this series on Python, we've covered what Python is,
installed software, and worked with operations. In this video, we'll be discussing
variables.


What is a Variable?

A variable is a container where you can store values. For example, we can store 2 in a
variable called "x".


Variables are useful because they allow us to change the value of the container, and we
can use them in operations. For instance, if we have x = 2 and y = 3, we can add them
together: x + y = 5.


Variables can store different types of values, such as integers and strings. We don't
need to define the type of the variable since it automatically takes the value of whatever
we assign to it.


Using Variables in Operations

We can use variables in operations just like we do with numbers. For example, we can
change the value of x from 2 to 9.

, We can also use underscores to represent the output of the previous operation. For
example, if we add x + 10, we can use the output of that operation (19) in another
operation: 19 + y = 22.


We can also fetch individual characters from a string stored in a variable using square
brackets. The numbering of characters starts at 0. For example, the first character of
"youtube" is "y" and the last character is "e". We can also use negative numbers to start
counting from the end of the string.


Working with Strings in Python

Let's start by looking at how to access specific characters in a string using index values:


● To access the first character, we use index 0.
● To access the second character, we use index 1, and so on.
● We can also use a colon to access a range of characters. For example, 0:2
will give us the first two characters.

It's important to note that the ending value in a range is exclusive, meaning it will not be
included in the result. If we want to access the first three characters, we would use 0:3.


If we don't specify an ending value, the range will go until the end of the string.


If we specify an ending value but not a starting value, the range will start at the
beginning of the string.


If we try to access characters outside the range of the string, we will get an error.


While strings in Python are immutable, meaning we cannot change individual
characters, we can concatenate strings and print them out in different ways.


We can also use the built-in len() function to find the length of a string.

Written for

Course

Document information

Uploaded on
December 2, 2023
Number of pages
7
Written in
2023/2024
Type
SUMMARY

Subjects

$6.29
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
rcdanteff

Get to know the seller

Seller avatar
rcdanteff Thamari higher secondary school
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

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