>> Let's get in and take a look at probably one of
the most common things that you'll be doing in programming,
and that is working with strings.
Now, when it comes to strings and
actually just variables in Python,
it's relatively straightforward to
take a string and store it inside of a variable.
Now as a real quick aside,
if you're not already familiar with variables,
variables windup acting as placeholders
inside of your code for some values.
So in my case,
first name is going to wind up being "Christopher".
Now, one of the things that will make Python
unique is the fact that you
don't have to use any form of
a keyword or otherwise to declare a variable.
You just simply give it a name,
set it to some value,
voila, you've created a variable that's all there is to it.
You'll also notice my string
literal over here on the right-hand side,
and you'll notice that I'm using single quotes here.
Again, you can use single quotes or double quotes,
doesn't matter which, but you want to be consistent.
For me personally, I really like using single quotes.
I just think it reads
a little bit better than having double-quotes.
Maybe I don't even have a good reason as to why.
I just think it looks better with
single quotes rather than double-quotes.
If you want to use double-quotes,
you're not going to hurt my feelings at all.
It's your code. Just simply again be consistent.
Now if you want to take two strings and combine them together,
you can do that by just using the plus operator.
So you'll notice in my code that I've got
my first name and my last name,
and then you'll notice that I'm going ahead
and I'm calling "Print," and I'm combining
that first name and last name together just by using
that little plus sign that you see right there.
Let me just grab my pen again so that way I can circle it.
That little plus sign will bring that together.
Now that works with both variables,
as well as with string literals.
So if I want to bring together a string literal of
"Hello" and a couple of spaces along with my strings,
then I can also do that just by using
that exact same plus operator.
One last little side-note on our variables.
You'll notice that we're using a word,
an underscore, and then a word.
When you're creating variable names,
you want to make sure that they're nice and clear,
and if they are going to need multiple words to make it clear,
convention in Python is always lowercase,
and with that underscore that you see there.
Now, if you want to modify a string,
maybe convert everything into
uppercase letters, lowercase letters,
capitalize just the first word,
or potentially count all of the instances of a particular string.
In this case the letter a,
you can do that by using upper, lower, capitalize,
encount, respectively, and down below
you'll see the results of doing each one of those.
Then finally, if you want to bring all of that together,
you can still do
that string concatenation just the way that we've seen previously,
and even bring in values from the outside world.
So in this little code example here,
what you're going to notice is we're going to read in
the first name from the input window.
So whatever it is that the user types in will bring that in.
We'll do the exact same thing with
the last name and print that out,
and then you'll notice that we can
properly capitalize everything by
utilizing that capitalize function that you see there,
and you'll notice the results,
that if I type in Christopher in all uppercase,
Harrison in all uppercase,
and then I wind up calling capitalize,
it will just capitalize that first letter.
So that's how you can get in and start working with
some neat little strings inside of Python.
Now what I want to do is go off,
do a little bit of a demo,
and then we'll actually come back and take a look at
one last advanced configuration that you can do with strings.