Posts

Showing posts from November, 2017

'if' 'else' 'elif' Python 3

Image
If So, as you can see we’ve got the output printed ‘You are old enough to vote’ and once we’ve got the age in the numeric format, we can actually use the greater than, and the equal, as we’ve used here, to actually check to see whether it is greater than or equal to 18, and we’re doing that using if statement, with a condition to check. So, if the condition is true, in this case the age was greater than, or equal to 18. Then, we’re printing the message that you’re old enough to vote. If the age is less than 18, nothing happens. It actually would go into the next line. Else Now, we can put in something called an else. So, how the program works is, it comes to and looks for the ‘if’ condition, and if that is true than that line got executed, not the next line with the else condition but if the age entered is not greater than or equal to 18, we get the second part. So, basically if the first condition got false than it comes to the second condition. Elif Now,...

String Slicing and Picking sub-string in Python3

Image
Picking Sub-String Now, we will pick individual character or sub-string from string. So, lets see, You might be thinking, why is that ‘g’, because we specified the third character, so shouldn’t that be counting from left to right, ‘B’ is the first character, ‘e’ is the second and ‘n’ is the third and in actual fact ‘g’ is the fourth character. Now you are thinking then why we say that ‘g’ is the third character. It’s actually usual for programming languages to start counting at zero and not at one. So that tiger zero is ‘B’. So we’ll actually go and see that, So there’s 12 character in ‘Bengal Tiger’, numbered from 0 to 11 and if we try to print 12 number character, then you’ll get an error. The other thing as you can do is count backwards. So, what’s happened is that it started here at position zero and goes to negative one. Negative one goes all to the way to the end of the string and starts counting from end. So we get the letter, which is t...

Integers and Float in Python3

Image
Let’s move on to variable types. Python has several built-in data types. Data types can be classified as numeric, sequences, mapping, files, classes, instances and exceptions. You’ll be introduced to all of these as this tutorial progresses but now, we’ll look at numeric data types and sequence type. String being a sequence type which we’ve looked at before. Integers So, start with the basic data type, its integer. An integer being a whole number, a number that hasn’t got any decimal points.  So, an integer is just a whole number. It’s a number having no fractional part, where as a float is another name for a real number. That is a number having a fractional part after the decimal point. There is a very small number of computer languages that make no distinction between real numbers and integers. In the computers, computations using integers these whole numbers, are significantly faster than using floating point numbers. That’s the reason we are distinguishing bet...

Variable in Python3

Image
The instructions that you typed in will be stored in one area of memory, but also the data that it’s going to work on, the variables that you’ve typed in, will be stored somewhere else in memory. So the variable, the name that assigned is just really a way to give a meaningful name to an area of memory into which we can place certain values. There are few rules to keep in mind when you actually created them. The actual name has to start with either a letter, it could be upper or lower case, or an underscore but we can’t start that with the number. We can use numbers in our variable names, just not as the first letter. Now the other important thing to consider here is that we could type a variable name called ‘Myname’ with uppercase M and that’s different and distinct to lowercase ‘myname’ variable. Now, in terms of the memory allocation, it happens at the point when you’ve initialized it. In other words once you’ve typed in the variable name and put an equal and the...

String Part 2 in Python3

Image
There is a special character called backslash character, it has a special meaning in strings, it's used to escape the character that follows it to give that character special meaning. The backslash character provide us a new line. So, let's see. Now, as you can see \n has actually caused the cursor to start on the next line. So, for each one of those \n's we added that actually spit onto a separate line each time we did it. Now, we'll do the same with tab character. It's used a standard tab function which you’ve probably seen in a word processor before to tab things out which is a way of sort of organizing things in a certain position. You can also use that backslash to escape special characters such as quote and double quotes, and that’s useful if you’ve got a string containing both characters. Let me show the example. So here, if we are using both single quotes and double quotes in a particular string which you may want ...

String Part 1 in Python3

Image
Strings are enclosed with either double or single quotes. You can use any of the quotes. But if you use single quote on the middle then you have to use double quotes to enclose it and if you want double quote. If you start a string with one type of quote then you have to end it with that type of quote. The other thing you can also do is you can concatenate strings, you can make a string longer by actually putting two string together. Here are two different independent strings and the plus actually adds then both together to form a master string. Now, we will store the strings in variables. Now, we put some space. Now, come to the comment, comment is where you've want something to add to remind yourself or give you some information about a particular bit of code. You just have to put hash and type something just like. And anything after the hash, that entire line is ignored but the computer. Let's now use another function, we will...

Say Hello to 'hello world' in Python3

Image
Now, start with 'hello world'   To get the output in the python shell you can press F5 and then you have to save the file then you get the output. It is the easiest of the program in python. Print keyword helps to print the output in the screen. There are a few important basics to understand. So, python has mathematical functions, like round, to round the number of digits after the decimals point, char to convert characters to the numerical representation and many more. For string you have to provide a value in parenthesis as you saw there in the 'hello world' in parenthesis, it is a string that's why, we actually have to put a single quote to the left and to the right of the string to tell python that this was a string. But we can also put in numerical numbers if we want it to actually be computed by python.

Install Python 3.6 IDLE

Image
Step 1 - Go to you browser and just type "Python Download". Step 2 - Now just click to the 'Download Python 3.6.3 and later if you got the new version then you can install that. Step 3 - Click on the 'Add Python 3.6 to PATH'. Step 4 - Then the Setup Progress get start. Step 5 - Then go to the Window's menu and click to the 'IDLE Python 3.6'. Step 6 - Then just to check, that Python IDLE is working, type 5+5 then you'll get the output.  Step 7 - After, click to the File in the Python shell, then select to 'new file'. In Python shell you get the output right away when you click enter but in file you can right multiple lines of code. 

Introduction to Python3

1. It's an object oriented interpreted language and really it's quite easy to use in terms of other language's and also run's on a lot of many operating system's including Mac, Window's, Linux etc. 2. The good thing about python is that it supports a lot of basic data types, such as number and strings. But also, it supports more complex types, like lists and dictionaries, that can greatly simplify data processing and it is object oriented so, it does support that fully and allows multiple inheritance. 3. ‎The other thing is that the data in python is strongly typed, so if you add a number and a string, you'll actually get an error. ‎It is simple to use yet very powerful.