Learn all the basics of python – Python beginners, let’s learn together (3)

Learning doesn’t stop, at any age!

Learning a little each day adds up!

In our last session, we learned variables in Python and how to use it. In today’s session, we will learn how to use String in Python.

A string in Python is a sequence of Unicode characters. Unicode was created in order to include every character in all languages and bring encoding uniformity. Python Unicode can teach you about Unicode. In Python, how do you make a string? Strings are formed by enclosing characters in single or double quotes.

Now let’s get some coding done.

print(“I am XRKnows!”)
String1 = “I am XRKnows!”
print(“String1”)
print(String1)

I’m using Spyder in your editor, typo or copy above code. I recommend that you type one line and then execute it. You should see the following output for each of the code lines above.

I am XRKnows!
String1
I am XRKnows!

The first print, as you can see, is a string with two double quote marks. In the 2nd line, the value “I am XRKnows!” is assigned to a string named String1. At this point the string String1 is defined and assigned with a value. What’s do you see after executing the 3rd line? Yes, “String1.” Why it is printing String1 instead of the string value “I am XRKnows!”? Yes, it was inside two double quotes. If you put some value within two double quotes, then the values within the double quotes will be treated as string values. In other words, the String1 is treated as a string value instead of a defined variable. What do you see after you executing the last line? Yes! This code print out the string that stored in String1 variable!

Now after the last line of print, let’s type below last two-line codes into your editor, execute them after you are done copying or typing.

print(“I am XRKnows!”)
String1 = “I am XRKnows!”
print(“String1”)
print(String1)
String1 = “I am XRKnows and I am a pet lover!”
print(String1)

What result do you see?? Yes. If you assign a new value to a variable that was assigned with a different value before. The variable will now contain the newly assigned values. In this case, the “I am XRKnows and I am a pet lover!”

Okay! I also learned Function today, however, I would just stop here for you to digest variables. See you in next session.

Okay! Today I also learned Function, but I’ll leave it at that for you to digest variables first. We’ll see you in the next session to learn Function in Python with me. 

Happy learning!! Let’s learn and grow together!

1 thought on “Learn all the basics of python – Python beginners, let’s learn together (3)”

  1. Pingback: Learn all the basics of python – Python beginners, let’s learn together (4) – XRKnows

Comments are closed.