Some basic arithmetic operations in Python 2.7
Addition
>>> 7+14
21
Subtraction
>>> 14-7
7
Multiplication
>>> 7*14
98
Division
>>> 14/7
2
Floor division
>>> 15//7
2
Exponent
>>> 7**2
49
Working with equations
>>> x=7
>>> y = 14
>>> x*y
98
>>> x=7
>>> y=14
>>> z=x*y
>>> print z
98
>>> x=14
>>> y=7
>>> z=(x+y)*x
>>> z
294
Comparison operations in Python 2.7
>>> 7==7
True
>>> 7==14
False
>>> 7<7
False
>>> 7<14
True
>>> 14>7
True
>>> 7<14>6
True
I believe I covered most of the arithmetic operations in Python 2.7. I am providing only examples because I believe it's the best way to learn. You will notice that I am giving very basic examples. This is because I want you to advance slowly and to start loving programming in Python.
Python is widely spread programming language used in many branches and from thousands of programmers. Earning potential with Python is unlimited. You can apply for projects everywhere. you can even create the projects and starting earning thousands of dollars.
Feel free to contact me if you have any questions.
Sunday, September 11, 2016
Saturday, September 10, 2016
Python 2.7 Basic Examples
Python is very progressive programming language. It's widely used in many areas.
In this blog post of "Python tutorials" I post some basic examples that will help you to get some basic knowledge and understand Python syntax. These examples are for Python 2.7 version.
In this blog post of "Python tutorials" I post some basic examples that will help you to get some basic knowledge and understand Python syntax. These examples are for Python 2.7 version.
Simple use of print command
>>> print
'I am wealthy'
I am wealthy
Use of print command with
'a' variable
>>> a = 'I
am wealthy'
>>> print a
I am wealthy
Join two variables with text
in one sentence and print it
>>> a = 'I
am'
>>> b =
'wealthy'
>>> print a
+ ' ' + b
I am wealthy
Multiply 'a' variable that
contain text
>>> a = 'I
am wealthy'
>>> print
a*5
I am wealthyI am
wealthyI am wealthyI am wealthyI am wealthy
Print more words at once
>>> print
'wealth', 'health', 'forgiveness'
wealth health
forgiveness
Using '\' to separate two
words with empty place
>>> print
'wealth\thealth'
wealth health
Using '\n' to separate two
words in two rows
>>> print
'wealth\nhealth'
wealth
health
Print a sentence that
contain '
>>> print
'it\'s good to forgive'
it's good to forgive
Print a sentence that
contain '
>>> 'it\'s
good to forgive'
"it's good to
forgive"
Print sentence surrounded by
'
>>> print
'\'I am wealthy\''
'I am wealthy'
Check if a word starts with
certain alphabet/s
>>>
'wealth' .startswith('w')
True
>>>
'wealth' .startswith('n')
False
>>>
'wealth' .startswith('weal')
True
Check if a word ends with
certain alphabet/s
>>>
'wealth' .endswith('h')
True
>>>
'wealth' .endswith('l')
False
>>> 'eal'
in 'wealth'
True
>>> 'l' in
'health'
True
Check how many time some
alphabet/s are in a sentence or words
>>> 'wealth
health forgive good love humble smart'.count('h')
4
>>> 'wealth
health forgive good love humble smart'.count('wealth')
1
Convert lower alphabets to
upper
>>>
'wealth'.upper()
'WEALTH'
Convert upper alphabets to
lower
>>>
'WEALTH'.lower()
'wealth'
Capitalize first alphabet in
a word
>>>
'wealth'.capitalize()
'Wealth'
Capitalize each first
alphabet in a list of words
>>> 'wealth
health good'.title()
'Wealth Health Good'
Replace alphabet/s or word/s
with others
>>> a = 'I
am wealthy'
>>>
a.replace('wealthy', 'healthy')
'I am healthy'
Replace empty spaces
>>> a =
'wealth health goodness forgiveness love'
>>>
a.replace(' ', '')
'wealthhealthgoodnessforgivenesslove'
Other way to replace word/s
>>>
a.replace('love', 'I').replace('good', 'forgive')
'I forgive'
Subscribe to:
Posts (Atom)