Interactivity is the Key to learn Python

Interactivity can play a significant role on learning the language. I've worked to a minimalistic platform which gives you the ability to learn and complete tasks, review corresponding theoretical content and re-take any exercises (if needed). I don't like to work with grades or accomplishment titles. The platform is free to use for either personal or professional purposes.

Python Variables

We have four main types of variables but before we begin with that there are some things you need to be aware of before entering that section. Once you've installed python successfully you'll see that there is a program called Python IDLE installed too. Run that. You'll be displayed a console tab. This console receives commands given after those symbols ">>>" and by hitting "Enter" you run the command in real time, checking its results. I suggest to you, after completing each of these exercises to head over the IDLE to experiment, to become more familiar for later, when we'll proceed to the basic script writing. Something IMPORTANT: Python is case sensitive {term var is different from term Var}, so pay attention to it.
Types of variables:


A string can be defined as set of characters issued to an empty memory slot. Example: "Python is the best language ever", 'Python is for true developers', "%#@34", "OhMyGod", 'ThisIsSoSimple'. All these are strings. You must use quotes when declaring them. Double ("") or single ('') quotes. Your choice. There are some extra operations with strings. Slicing, addition and multiplication of strings.

>>>   myString = "YourName" or myString = 'YourName'

The term myString is a variable (an empty memory slot) which holds the term 'YourName'.

>>>   myString[0:4]
>>>   'Your'

The term myString starts counting characters from 0. 'Y' = 0, 'o' = 1, 'u' = 2 etc. We have been asked to extract the word 'Your' from the string. Using the [:] we can control these string's limits. So we enter 0 to start from the beginning of the string. So we enter [0: ]. Now we need to count what number represents r and add 1 to it in order to contain 'r' as well. The number is 4. Let's enter it [0:4]. And BOOM! We've extracted the word 'Your' from the string 'YourName'. Extra possibilities:

>>>   myString = "YourName"
>>>   myString[:]
>>>   myString[:-1]
>>>   myString[-1:]

String Addition & Multiplication

Addition: The operation described is pretty straight forward. We declare two variables a and b and loading them with some words. Then with "+" operator we adding them together. Multiplication: We take a string and multiply it by a number.


>>>   a = "Hello "
>>>   b = "World!"
>>>   a + b
>>>   "Hello World"

Pay attention to the spaces. When constructing and displaying sentences automatically you need to account for spaces between words. We don't write, 'Whatisyourname', right? Now, observe the "Hello " from above. If I hadn't place that space there, the sentence would be without any logical separator. Like so...

>>>   a = "Hello"
>>>   b = "World!"
>>>   a + b
>>>   "HelloWorld"

All of the above apply with the multiplication of a string as well...


>>>   a = "Hello"
>>>   a*2
>>   a*4

Try it!

Declare a variable myApple and set it to "apple". Use double or single quotes.

Integers & Long Numbers

Integers are all the numbers without a floating point. Use 'long' notation when the number to be assigned is too large, e.g 29084808909090. Long numbers can be used for hex numbers as well as for octals.I = {-2,-1,0,1,2} Integers are usually used as counters or for rounding floating points. What I mean by that is, let's say, you have a number 1.34 and you don't want the .34 in the end. You just need to hold the 1 part. You can convert it to an integer term which will spit out 1.

>>>   myNumber = 88

The term myNumber again is a variable (an empty memory slot) which holds the term 88.

Try it!

Declare a variable carbons and set it to 938.

Float Numbers

Floats are all the integer numbers with a floating point.
F = {-2.2,-1.3,0,1.3,2.498}
Floating points are typically used to describe precision (from metrics to vector calculus). Example: Once a month, a company releases statistics to predict and revise its productivity and net cost rates. All these terms can't be described as an integer. We can't have always 5000$ net costs. Will probably have cents too. However, in some cases, you are able to describe a percentage, but be minded that 5% of annual revenue corresponds to a float number (0.05). Use them wisely!

>>>   myNumber = 88.00

The term myNumber again is a variable (an empty memory slot) which holds the term 88.00.

Try it!

Declare a variable annualRates and set it to 0.06985.

Complex Numbers

Complex numbers are used in algebra and calculus. Example: '3.88 + 98j'. You need to use only "J" or "j" in the end. You're not allowed to use other letters to describe a complex number. "3.88" corresponds to the "Real" part of the number where "98j" is the "Imaginary" end.

>>>   myComplexNum = 5 + 3j

The term myComplexNum again is a variable (an empty memory slot) which holds the complex term5 + 3j.

Try it!

Declare a variable complexVar and set it to 3.45j.

Booleans in Python

Booleans can be defined as variables which can take only two distinct values. A boolean variable contains a designation of True, False which are equivalents to 1, 0. True = 1 and False = 0. Their role varies, but usually can be used for validation checks or confirmation analysis. Example: A car will crash, if fall from a cliff. That is a fact which is True. The car will get wrecked. Another example: A tax officer wants to shut-down a program, but will only do so if the number 1 is given. There is a validation process which checks whether the user enters 0 or 1 and acts accordingly.

>>>   youAreMarried = True

The term youAreMarried again is a variable (an empty memory slot) which can take only two terms. You can hold either the "True" or "False" term.

Try it!

Declare a variable singleMan and set it to False.
Remember: "True" or "False". Capital 'T' and capital 'F'.

Ungraded Python Quiz - Test what you have learned so far

Define a string variable named var and assign to it the phrase "Awesome". With all spaces, exactly as indicated.

The next task is to extract the word "some" from that string.

Write the command which will add a random string variable phrase to the var variable which you have already assigned. You don't need to assign phrase variable anywhere. Just include the word to the command.

Declare a variable myNum equals to 342

Declare a variable myPointingNum equals 45.9982

Declare a variable passTheQuiz to True or False(Whatever you like)

Create a variable imaginary and set it to 340 + 93.21j

? | Contact Me | © 2016