Thank you for reading this Article. 🙂
I have started learning Python and would like to share my knowledge here. I found this web-site is good & would like to write series of Articles on Python Programming.
This one is my first Article in this forum. 🙂
When I started learning Python, I was confused whether to start Python or “R” language. But finally decided to learn Python first. Of course, “R” is also good; but would like to start with Python first.
The very first question, I had “Where to start.?”.
I have looked into python.org & found very useful information. I have started reading the Tutorials & References mentioned in the website python.org. I felt this is the best place to start.
After that, the next question I had, “How to test what I learned.?”.
To speed-it up, I have started using “Interactive Shell”. I don’t want to install Python on my Computer at the moment; but would like to run Python code on-line. So I choose, “Interactive Shell” from python.org website. This will allow the user to write Python statements & execute them in the shell. This looks like below:
Python 3.6.0 (default, Jan 13 2017, 00:00:00)
[GCC 4.8.4] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
There is a shell prompt, “>>>” where we can write our commands or statements. Once hit the Enter key, the Interpreter execute the commands and display the results.
Displaying “Hello, World!”
The first command would like to run is printing “Hello, World!” message. I believe most of the people would like to start their first program by displaying “Hello, World!” message. 🙂
I found “print” is the function which is useful to display the message.
Python 3.6.0 (default, Jan 13 2017, 00:00:00)
[GCC 4.8.4] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> print(“Hello,World!”)
Hello,World!
>>>
🙂 That’s good. My first Python statement working fine.
I would like to run one mathematical expression. Which one to run.?… hmmmm….
Evaluating a formula (a + b)².
Would like to run this expression. I know (a + b)² means, a² + b² + 2ab. Would like to test this one on the shell prompt. I want to give simple values; 1 for a & 2 for b. The result should be 9. But how to give square on the prompt.?
I know, the operator “+” is for addition. But what would be the operator to calculate the square. Finally I found ** is the operator useful for this. This will calculate the power (exponential).
Python 3.6.0 (default, Jan 13 2017, 00:00:00)
[GCC 4.8.4] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> print(“Hello,World!”)
Hello,World!
>>> a = 1
>>> b = 2
>>> (a + b) ** 2
9
>>>
Good to see the expected result.
I would like to test another expression using strings.
Concatenating Strings
I read in the Tutorial, strings can be concatenate using “+” Operator. Let me try this on the console.
Python 3.6.0 (default, Jan 13 2017, 00:00:00)
[GCC 4.8.4] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> print(“Hello,World!”)
Hello,World!
>>> a = 1
>>> b = 2
>>> (a + b) ** 2
9
>>> “Hello, ” + “World!”
‘Hello, World!’
>>>
We can see the result as expected.
Let me Close this Article here. Would like to discuss more on Python in my coming Articles.
/Shijit/