Python strings and Python variables: 9 rules to remember | Python for Beginners (4:43)
Videos can also be accessed from our Full Stack Playlist 3 on YouTube.
Welcome. Today's question: How do you create text strings and variables in Python?
I'm Paul, and as we near 2 hours runtime in this Series, it's okay if you're frustrated we have yet to write a program. Trust me, I am too.
So in this video we'll get one under our belt, even though it's ultra-basic and just done at the Python Terminal.
I'll zip through how we got here, then cover 7 guidelines for creating variables and 2 for creating text strings.
(Commands in Linux)
(Symbols and functions in Python)
The next tutorial is on functions, like this funny looking
print() guy here,
which is, in fact, the focus of our very first program here.
So while I show you where we're headed and our planned software stack, I want to say that the frustration of starting slow is normal. In Data Science, for example, there are lots of hurdles in getting smart minded people to ditch their spreadsheet and learn real Data Science in a programming language.
There's the soft stuff like figuring out which books to buy, what classes to take, websites to visit and which YouTube resources to trust, which can be a headache all by itself.
Then there is the technical stuff, I'll poke around on this Linux server, highlighting our path with technical decisions like selecting the appropriate hardware, the operating system, setting up users and groups, which software languages to learn, selecting which versions to focus on, and the whole installation process, often a major stumbling block.
That's what we hit in the first 22 tutorials, which all leads us to here, our first program.
I'll bet that you've seen this before,
>>> print("Hello World!"),
maybe 90% of instructors start with it, but I'm not a conformist, so
this is how I'll start, with a two-liner.
I suggest following along in your Python, preferably version 3, because
some syntax is different, including this
Let's break down what happened there covering seven things you should know about variables.
First, the variable name here,
first_name, is on the left, and
whatever is on the right of the single equal symbol is assigned to it.
Here we assign a string of text. After
Enter Python stores it in memory.
Second, what's the best form to use? We could be lazy and do
y=2 with no spaces.
Or for better form, uses spaces like this
y = 2.
Here we assigned an integer to the variable
y, printing it if we don't need to
fancy it up with text.
Third, variable names should explain what they contain, like bucket names.
Fourth, once you reassign the variable, the old value is forgotten (y was assigned 2 above).
Fifth, variables must start with a letter or underscore, and that's it. Avoid all of the other characters, but numbers are okay afterwards.
y2 works, and so do math
y + y2.
Sixth, variables need to be one word, no spaces (or Python gives you an error).
Seventh, variables are case sensitive, so uppercase
First_Name and lowercase
first_name are not the same.
It's good form to start with lowercase letters.
While it's on my mind, to brush up, or learn those Linux commands from earlier, go here, Linux Essentials, and you'll find one hundred 3-4 minute command summaries and quizzes that sit in our Linux Playlist.
Let's talk about text strings.
First, they can be entered with single or double quotation marks.
Two choices are available because you may need to use an apostrophe
" in your string, and surround
it with the other, or you'll get an error.
Python assumed the string ended here
(with the second
Second, concatenation means adding text strings together with a plus
+, so let's add to the
print() is the name of the function
and it prints what's passed to it, inside parentheses, called an
So here is the stack we are adding to, one tutorial at a time.
In the next tutorial we will explore functions.
Have a nice day.
See more free learning at our YouTube Channel. Subscribe here.