Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts
Thursday, May 16, 2019
Python List is more than just a List
May 16, 2019
Python is the most popular programming language today, We can understand the growth of Python by it's continuously growing ratio of it's related fields like Data Science, Python Developer, Deep Learning Researcher and many more fields which are related to Python.

So lets talk about today's topic that is Python List. So if you don't know anything about Python List then I will recommend you to check the first tutorial on list.
So for Now, I am going to tell you a little bit more about Python List.
Python List is more than just a List :
Python 's List can make your Data Structure easy to implement, So let's try to take a deep dip inside this Python List, when we use a Python data structure that holds many Python objects, It can holds as many object, that's by it's called list, We can create a list of integers as follows.
In[1]: L = list(range(10))
L
Out[1]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In[2]: type(L[0])
Out[2]: int
L
Out[1]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In[2]: type(L[0])
Out[2]: int
Or, similarly, a list of strings: Which helps you to build a strong basic concept of Python List.
In[3]: L2 = [str(c) for c in L]
L2
Out[3]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
In[4]: type(L2[0])
Out[4]: str
L2
Out[3]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
In[4]: type(L2[0])
Out[4]: str
Because of the Python’s dynamic typing, we can even create Heterogeneous Lists also. Let's see the example of Heterogeneous List.
In[5]: L3 = [True, "2", 3.0, 4]
[type(item) for item in L3]
Out[5]: [bool, str, float, int]
[type(item) for item in L3]
Out[5]: [bool, str, float, int]
But this flexibility comes at a cost to allow these flexible types, each item in the list must contain its own type info, reference count, and other information—that is, each item is a complete Python object.
Again, the advantage of the list is flexibility:
because each list element is a full structure containing both data and type information, the list can be filled with data of any desired type.
The difference between a dynamic-type list and a fixed-type (NumPy-style) array is illustrated in the given image below.
Creating an Array's from Python List :
First, we can use np.array to create arrays from Python lists.
In[1]: import numpy as np
In[2]: # integer array:
np.array([1, 4, 2, 5, 3])
Out[2]: array([1, 4, 2, 5, 3])
In[2]: # integer array:
np.array([1, 4, 2, 5, 3])
Out[2]: array([1, 4, 2, 5, 3])
Remember that :
Unlike Python lists, NumPy is constrained to arrays that all contain the same type. If types do not match, NumPy will upcast if possible (here, integers are upcast to floating point).
In[1]: np.array([3.14, 4, 2, 3])
Out[1]: array([ 3.14, 4. , 2. , 3. ])
Out[1]: array([ 3.14, 4. , 2. , 3. ])
We can also Set the data type of our resulting Array at the initialize time using dtype Keyword.
In[9]: np.array([1, 2, 3, 4], dtype='float32')
Out[9]: array([ 1., 2., 3., 4.], dtype=float32
Out[9]: array([ 1., 2., 3., 4.], dtype=float32
Here is the one way of initializing a multidimensional array using a list of lists :
In[7]: # nested lists result in multidimensional arrays
np.array([range(i, i + 3) for i in [2, 4, 6]])
Out[7]: array([[2, 3, 4],
[4, 5, 6],
[6, 7, 8]])
np.array([range(i, i + 3) for i in [2, 4, 6]])
Out[7]: array([[2, 3, 4],
[4, 5, 6],
[6, 7, 8]])
At Last Thanks for Reading...
Monday, January 14, 2019
Learn Python from Zero to Hero
January 14, 2019
This is the 6 part of Python tutorial series, Learn Python from Zero to Hero. If you want to learn Python from scratch you can check our previous tutorials on Python. If you want to read from starting click the given link below.
Learn Python from Zero to Hero Part 1.
Learn Python from Zero to Hero Part 2.
Learn Python from Zero to Hero Part 3.
Learn Python from Zero to Hero Part 4.
and the Last one Learn Python from Zero to Hero Part 5.
We all know Python is the rich programming language for data science, If have dream like many of others to become a data scientist in future or want to learn data science, Python is the best way to start with, Python have many libraries which makes Python most popular programming language for data science, Python's libraries makes data science easy to learn.
In this part we will learn What is list or tuples in Python ?, Python support four type of collections List, Tuples, Set and Dictionary, Now you are exited to know what are these collections ?, If you are exited it means you love programming like me. But if you are NOT exited than you are Lazy Person.
Don't be sad i have a little bit Motivation for You. #Hahahaha.
I will always choose a lazy person to do a difficult job because a lazy person will find an easy way to do it.
Whenever there is a hard job to be done I assign it to a lazy man; he is sure to find an easy way of doing it.
Bill Gates.
So if you are exited to know what is List, Tuples, Set or Dictionary ?, than Stay with me and keep calm, We will learn all of them one by one, So let me start with List or Tuples in this post we will cover remains Set or Dictionary in next post.
So Let's Begin
List :
As I told you before list is a part of collections, This List is ordered or unchangeable in Python, This List is also allow the duplicate members, In Python List written around the square bracket, This list in Python is very important to understand.If you do programming before than you already know about what is array ?, These array's are very important in programming. Because Python does not support data type than python have this List feature, This List works similar to array's.
Example :
list = [ 'Apple', 'Banana', 'Mango', 'Papaya', 'Orange' ]
print ( list )
print ( list )
List also contains list or tuple inside list and List able to contains all kind of data types in a single list, You can better understand it by the given example below.
list = [ 'Hello', 'First List', [ 'Hey', 'Second List' ], 3, 66.78, 'A',99.12, 'C' ]
print ( list )
list [4] = "Syntaxios" # you can change list at any time, Because list is changeable.
print ( list )
print ( list )
list [4] = "Syntaxios" # you can change list at any time, Because list is changeable.
print ( list )
Tuples :
Tuples are also the part of collections, Tuples are ordered or unchangeable, and Tuples also allow the duplicate member, Tuples should be written around the brackets that is rounded bracket.Example
tuple = ( 'Apple', 'Banana', 'Mango' )
print ( tuple )
print ( tuple )
Tuple also contains the tuples or list inside the tuple, Let's understand tuple by the given example below.
tuple = ( 'Tuple', 56, 66.7, [ 'list', 7, 11.7 ], 'A', 75, ( 'Another', 'Tuple', 'G', 77 ), 'End' )
print ( tuple )
tuple [3] = " Integer 56 " # you can not do this because tuples are Unchangeable.
print ( tuple ) # error
print ( tuple )
tuple [3] = " Integer 56 " # you can not do this because tuples are Unchangeable.
print ( tuple ) # error
As you can see the given example of List and Tuples. The list and Tuple both are able to contains each others. List is Changeable or Tuples are Unchangeable in Python.
Friday, December 28, 2018
What is immutable String ?
December 28, 2018
Hello World,
The word immutable can confuse you in Python, What does this immutable meaning in Python ?, It looks strange for you, Don't worry Never loose your SMILE, in this post i am gonna make it clear, We all know about strings, what is strings ? and where to use these strings ?, We are unaware of the word immutable, what exactly does it mean ?. So Let's Start.
As the name immutable stands for unchangeable, The immutable meaning is, it is unchangeable it will create the same copy of variable, But no-one can update the same variable in Python, As we all know that We need this update concept in programming, sometimes we need to update our variables in our program,we simply update our variable like int a = 1, than a = 7, this kind of thing.
We can update our variables in Python too, Now the term string, As we talk about in this post what is immutable string ?, As now you know what is immutable string ?.
In Python we can not update our string variable, we can update integer, float etc. each type of variable in Python But not String we can not update string variables in Python, Because Strings are immutable in Python.
So Let's See the Example of immutable string in Python :
But what if you want to change something in the given string, You can do that using replace() method. Let's See the example of replace() method.
At Last Thanks for Reading, Share with others if think it is useful thing to know.
The word immutable can confuse you in Python, What does this immutable meaning in Python ?, It looks strange for you, Don't worry Never loose your SMILE, in this post i am gonna make it clear, We all know about strings, what is strings ? and where to use these strings ?, We are unaware of the word immutable, what exactly does it mean ?. So Let's Start.
What is Immutable String in Python ? :
The String is immutable which means that once created than it can not be changed, The object created as a String is stored in the constant String Pool.Python VS Java's Immutable String :
Every immutable object in java is thread safe, that implies string is also thread safe, Strings can not be used by two threads simultaneously string once assigned can not be changed.As the name immutable stands for unchangeable, The immutable meaning is, it is unchangeable it will create the same copy of variable, But no-one can update the same variable in Python, As we all know that We need this update concept in programming, sometimes we need to update our variables in our program,we simply update our variable like int a = 1, than a = 7, this kind of thing.
We can update our variables in Python too, Now the term string, As we talk about in this post what is immutable string ?, As now you know what is immutable string ?.
In Python we can not update our string variable, we can update integer, float etc. each type of variable in Python But not String we can not update string variables in Python, Because Strings are immutable in Python.
So Let's See the Example of immutable string in Python :
# Immutable String in Python.
name = "Syntaxios"
print(name)
name[0] = "B" # Here it gives error. Because strings are immutable in Python
print(name)
name = "Syntaxios"
print(name)
name[0] = "B" # Here it gives error. Because strings are immutable in Python
print(name)
But what if you want to change something in the given string, You can do that using replace() method. Let's See the example of replace() method.
# replace() method example.
print(name)
print(name.replace("S", "B"))
print(name)
print(name.replace("S", "B"))
At Last Thanks for Reading, Share with others if think it is useful thing to know.
Thursday, December 27, 2018
Learn Python from Zero to Hero Part 5
December 27, 2018
Hello World,
This is the another part of Python tutorial series, Learn Python from Zero to Hero, This Python tutorial series will help you to learn Python from basic to advance, This tutorial series will also help you to enhance your programming skill in python, If you want to learn Python from Zero or you actually don't have any idea where to start ? So don't worry about it, Because #Abhi Hum Zinda Hain #Hahahaha.
I divide this tutorial series into a parts, It makes it better, Because you don't have to loose your mind to find which is the first part of this tutorial ?, where should i start learning this tutorial ?, You don't need to waste you time into it. So let's enjoy this tutorial series.
Learn Python from Zero to Hero Part 1.
There is our another part of this series.
Learn Python from Zero to Hero Part 2. and Than you can move on to the Part 3 and Than the last one that is Part 4.
In this Part we will learn about String Method, What exactly String Method is ?, Where to use this String Method concept ?. Let's learn with your smiley face.
These String Methods are present in Python 2 to Python 3.6. But the Python 3.7 contains some extra features, function or methods.
breakpoint() function.
time_ns() - time function with Nano Second.
Python 3.7 is also have new Typing Modules or Generic Types.
_mro_entries_() :
Python 3.7 also have some file updation.
.pyc file - It is a bytecode cache files.
Hash-based .pyc files.
These .pyc file may be generated with py compile or compileall. For more you can check the Python 3.7's documentation.
At Last Thanks for Reading and don't be cheap to sharing with others...
And This Line are going to bore both of us, If you have any question about this post, Let me know in the comment section below.
This is the another part of Python tutorial series, Learn Python from Zero to Hero, This Python tutorial series will help you to learn Python from basic to advance, This tutorial series will also help you to enhance your programming skill in python, If you want to learn Python from Zero or you actually don't have any idea where to start ? So don't worry about it, Because #Abhi Hum Zinda Hain #Hahahaha.
Let me start with the Basics, click here to learn some basic about Python, Or you can also check our previous tutorial whatever you miss before, Click the given links below to check our full Python tutorial series Learn Python from Zero to Hero.
I divide this tutorial series into a parts, It makes it better, Because you don't have to loose your mind to find which is the first part of this tutorial ?, where should i start learning this tutorial ?, You don't need to waste you time into it. So let's enjoy this tutorial series.
Learn Python from Zero to Hero Part 1.
There is our another part of this series.
Learn Python from Zero to Hero Part 2. and Than you can move on to the Part 3 and Than the last one that is Part 4.
In this Part we will learn about String Method, What exactly String Method is ?, Where to use this String Method concept ?. Let's learn with your smiley face.
String Methods :
There are some string methods in Python, which will makes Python rich programming language, Let's See these String Methods and for which kind of tasks these methods are used for ?.String Method | Description |
---|---|
count() | Return the number of times the specific character is used in a string. |
upper() | Convert the string into Upper Case. |
lower() | Convert the string into Lower Case. |
capitalize() | Converts the first character into Upper Case. |
casefold() | Converts the string into Lower Case |
title() | Convert the string into the Title Case. |
split() | Splits the string at the specific separator and return a list. |
splitlines() | Splits the string at the line break and it also return a list. |
startswith() | Return true if the string starts with specific value. |
endswith() | Return true if the string starts with specific value. |
strip() | Removes the all the spaces from the string. It is a trim version of string. |
lstrip() | Removes the all the left spaces from the string. It is a left trim version of string. |
strip() | Removes the all the right spaces from the string. It is a right trim version of string. |
replace() | Replace a specific value with a specific value. |
find() | Find / Searches the specific value from the string and return the last position. |
rfind() | Searches / Find the specific value from the string and return the last position. |
format() | Formats the specific value from the string. |
format_map() | Formats the specific value from the string. |
partition() | Returns the tuple where the string is parted into three parts. |
rpartition() | Returns the tuple where the string is parted into three parts. |
center() | Return a centered string. |
index() | Searches the string from a specified index and Return the position |
rindex() | Searches the string from a specified index and Return the last position. |
encode() | Returns the encoded version of string. |
expandtabs() | Sets the tab size of string |
isalnum() | Returns true if all the characters are alphanumeric in string. |
isalpha() | Returns true if all the characters are alphabets in string |
isdecimal() | Returns true if all the characters are decimal in string. |
isdigit() | Returns true if all the characters are digits in string. |
isidentifier() | Returns true if the string is an identifier. |
islower() | Returns true if all the characters are in Lower Case in string. |
isnumeric() | Returns true if all the characters are numeric in string. |
isprintable() | Returns true if all the characters are printable in string. |
isspace() | Returns true if all the characters are whitespaces in string. |
istitle() | Returns true if string follow the title rule. |
isupper() | Returns true if all the characters are in Upper Case in string. |
ljust() | Returns a left justified version of string. |
maketrans() | Returns a translation table to be used in translations. |
swapcase() | Swap cases, lower case becomes upper case and vice versa. |
translate() | Returns a translated string. |
zfill() | Fills the string with a specified number of 0 values at the beginning. |
Remember one thing Strings are immutable in Python. If you don't know What is immutable String ?, Please click here to know What is Immutable String ? or Why Strings are immutable in Python?. Let me clear it.
These String Methods are present in Python 2 to Python 3.6. But the Python 3.7 contains some extra features, function or methods.
Python 3.7 :
Python 3.7 contains some new functions, methods and files which are absent in Python 3.6, Let's See what these functions, methods and files are ?.breakpoint() function.
time_ns() - time function with Nano Second.
Python 3.7 is also have new Typing Modules or Generic Types.
Python 3.7 Methods :
_class_getitem_() :_mro_entries_() :
Python 3.7 also have some file updation.
.pyc file - It is a bytecode cache files.
Hash-based .pyc files.
These .pyc file may be generated with py compile or compileall. For more you can check the Python 3.7's documentation.
At Last Thanks for Reading and don't be cheap to sharing with others...
And This Line are going to bore both of us, If you have any question about this post, Let me know in the comment section below.
Monday, December 24, 2018
Learn Python from Zero to Hero Part 4
December 24, 2018
Hello World,
This is the Fourth part of the Python Tutorial series Learn Python from Zero to Hero, If you want to Learn Python from ZERO, Check my previous part of this tutorial series, Click the given link below.
Learn Python from Zero to Hero Part 1.
Learn Python from Zero to Hero Part 2.
Learn Python from Zero to Hero Part 3.
So let's see
There are different syntax of string formatting in Python for different version, The Python 3 version have different way and Python 3.6 have it's own way of using string formatting, Both version of Python have different syntax, Let's take a look How String Formatting uses in Python ?.
At Last Thanks for Reading and Don't be cheap to share with others...
This is the Fourth part of the Python Tutorial series Learn Python from Zero to Hero, If you want to Learn Python from ZERO, Check my previous part of this tutorial series, Click the given link below.
Learn Python from Zero to Hero Part 1.
Learn Python from Zero to Hero Part 2.
Learn Python from Zero to Hero Part 3.
String Formatting in Python :
Python is the rich programming language, It is the collection of rich feature of programming , It is the real world programming like Java, Now here is the one of the best rich feature of Python that is String Formatting, String formatting is one of the best feature of Python Which I personally loved.So let's see
Whats is String Formatting ? :
Let me explain string formatting in a very short description, String Formatting allows multiple substitution and value formatting. This string formatting in Python uses the format() method for string formatting in Python 3.There are different syntax of string formatting in Python for different version, The Python 3 version have different way and Python 3.6 have it's own way of using string formatting, Both version of Python have different syntax, Let's take a look How String Formatting uses in Python ?.
# String Formatting in a Common way.
name, age ="Syntaxios","2017"
name, age ="Syntaxios","2017"
print("Name : "+name+" Age : "+age)
String Formatting in Python 3 :
# String Formatting in Python 3.
name,age = "Be Syntaxios","18"
print("Name : {} and Age : {}".format(name,age))
# Here if you change the order, You got a different output.
print("Name : {} and Age : {}".format(age,name))
name,age = "Be Syntaxios","18"
print("Name : {} and Age : {}".format(name,age))
# Here if you change the order, You got a different output.
print("Name : {} and Age : {}".format(age,name))
Here {} boxes are called Placeholder, Sometimes It also known as Black Boxes.
String Formatting in Python 3.6 :
# String Formatting in Python 3.6.
name, age = "syntaxios.blogspot.com","23"
print(f"Name is {name} and Age is {age}") # don't forget to add 'f ' at starting.
# String Formatting in Python 3.6.
name, age = "Aman Singh Rajawat",22
print("Name is : %s"%name) #Single Variable
print("Name is : %s"%name) #Single Variable
print("Name %s and Age %d "%(name,age)) #Multiple Variables
Here %s stands for String and %d stands for Integer.
At Last Thanks for Reading and Don't be cheap to share with others...
If You have any question related to this post, Let me know in the comment section.
Previous Topic : Part 3 Next Topic : String MethodsSaturday, December 22, 2018
How to Install, Update or Uninstall Libraries in Python ?
December 22, 2018
Hello World,
Here everyone talking about Tensorflow, PyTorch or Matplotlib and many more Python Libraries for Artificial Intelligence, Machine Learning or Deep Learning etc. I asked many Python developers How to Install these libraries in Python ? How i can start learning these thing ? But no one told me the exactly way to install these libraries in my PC.
No-one give me the proper answer to How to install TensorFlow, PyTorch, Matplotlib ?.
When i asked to someone about packages who is already working on Python. Do you know ?, what was the alswer ? do wanna know ?.
Me : Hi Buddy! How to Install TensorFlow in my PC ?, I want to work on Artificial Intelligence or Machine Learning. So How to Install these Libraries ?,
He : Ahm, Hm, Ok, first of all you should install the PIP.
Me : What is PIP ?.
He : PIP is a library which is pre-installed with your Python, If you use the Python 2.4 or Greater version.
Me : Ok, Than What about TensorFlow, PyTorch or Other Artificial Intelligence or Machine Learning libraries ?.
He : Ahm, Hm, Good question ?, I am little bit busy right now, may we talk latter ?.
Me : It's Ok, ( Chal BC, Chutiya, Kuch Ni aata saale ko Chutiya banata h saala ), But from inside #Hahahaha.
Than I asked the same thing to one of my Best Friend "Ok Google", i did the same thing with my Best Friend, But he did not reply same thing as above #Hahahaha, But he also break my Heart, I break my 12 year Friendship with him, and make or Follow my own way.
Than I find the PIP, or TensorFlow, PyTourch etc in my Python, Suddenly I come up with the idea to install these libraries, Do you want to know too ?, So let's see some useful command.
Some Useful Command for Python :
Open Command Prompt and Type the Following Command and hit the Enter.
To Check Python is installed or Not ?.
How to Upgrade PIP on Window ?.
How to Upgrade pip on Mac or Linux ?.
How to manage Packages ?.
List of all Installed Packages.
To list of all Outdated packages.
To see the details about an installed packages.
To Install the new Packages.
To Upgrade an Outdated Packages.
To Completely Re-Install an Package.
To Completely Uninstall or Rid of an Package.
If you want to know more about the commands for managing the packages, Let me know in the comment box below.
At last Thanks for reading...
Here everyone talking about Tensorflow, PyTorch or Matplotlib and many more Python Libraries for Artificial Intelligence, Machine Learning or Deep Learning etc. I asked many Python developers How to Install these libraries in Python ? How i can start learning these thing ? But no one told me the exactly way to install these libraries in my PC.
No-one give me the proper answer to How to install TensorFlow, PyTorch, Matplotlib ?.
When i asked to someone about packages who is already working on Python. Do you know ?, what was the alswer ? do wanna know ?.
Me : Hi Buddy! How to Install TensorFlow in my PC ?, I want to work on Artificial Intelligence or Machine Learning. So How to Install these Libraries ?,
He : Ahm, Hm, Ok, first of all you should install the PIP.
Me : What is PIP ?.
He : PIP is a library which is pre-installed with your Python, If you use the Python 2.4 or Greater version.
Me : Ok, Than What about TensorFlow, PyTorch or Other Artificial Intelligence or Machine Learning libraries ?.
He : Ahm, Hm, Good question ?, I am little bit busy right now, may we talk latter ?.
Me : It's Ok, ( Chal BC, Chutiya, Kuch Ni aata saale ko Chutiya banata h saala ), But from inside #Hahahaha.
Than I asked the same thing to one of my Best Friend "Ok Google", i did the same thing with my Best Friend, But he did not reply same thing as above #Hahahaha, But he also break my Heart, I break my 12 year Friendship with him, and make or Follow my own way.
Than I find the PIP, or TensorFlow, PyTourch etc in my Python, Suddenly I come up with the idea to install these libraries, Do you want to know too ?, So let's see some useful command.
Some Useful Command for Python :
Open Command Prompt and Type the Following Command and hit the Enter.
To Check Python is installed or Not ?.
Python or python
How to Upgrade PIP on Window ?.
python -m pip install -U pip
How to Upgrade pip on Mac or Linux ?.
pip install -U pip
How to manage Packages ?.
List of all Installed Packages.
pip list
To list of all Outdated packages.
pip list -- outdated
To see the details about an installed packages.
pip show package-name
To Install the new Packages.
pip install package-name
To Upgrade an Outdated Packages.
pip install package-name -- upgrade
To Completely Re-Install an Package.
pip install package-name --upgrade --force-reinstall
To Completely Uninstall or Rid of an Package.
pip uninstall package-name
If you want to know more about the commands for managing the packages, Let me know in the comment box below.
At last Thanks for reading...
Thursday, December 20, 2018
Learn Python from Zero to Hero Part 3
December 20, 2018
Hello World,
If you want to learn Python from Zero to Hero, You are on the right place to learn Python, This Blog will help you to learn Python from Zero to Hero, Let's make learning fun with your smiley face.
So This is the third part of Python Tutorial, If you want to read Part1 or Part2 click the links below.
Learn Python from Zero to Hero Part 1
Learn Python from Zero to Hero Part 2
Variables in Python :
If you read little bit about Python than you know about it, that is Python does not support variable type, This make Python easy, You don't have to be confused about the variable types, OMG! which type of variable should i use there ?, Oh! No, I have again made a variable type mistake in my code Oh Shit!, But now you will not going to get any kind of variables error in your code, what i am talking about. Because Python gives you the freedom to #CodeYourself, So let's See How Python use variables ?.
print(num)
name = "Syntaxios Blog"
print(name)
Multiple Variables :
print("Name : "+name+" Age : "+age)
String Concatenation in Python :
String concatenation is one of the important thing in programming world, Because this String Concatenation did a good job for programmers, String Concatenation is useful topic for programmers, We need this String Concatenation for make our program compatible. Let's See the Example.
last_name = "Be Syntaxios"
full_name = first_name + last_name # String Concatenation.
print("Name : "+full_name)
User Input in Python :
The most important things in each and every programming language the User Input, Sometimes if you want to learn more than a one programming language at the same time, you can learn the more than a one language at a time you should basically learn the basic concept of the programming which you want to learn like User Input, Loops, a little bit about variables etc. you should only focus on the basic concept the particular language. The User Input the most important one also, How to take Input from User in Python ?. Let's See How ?.
print(" Hello : "+name) # String Concatenation.
Integer Input :
num_two = int ( (input("Enter the Second Number ? ") )
add = num_one + num_two
print("Addition is : "+str(add)) # Here we change the Integer into the String using the str function. You can not concatenate Integer with String that by we change the Integer into the String.
Float Input :
print(num1)
Multiple Input :
print("First Name : "+first_name+" Last Name : "+last_name)
print("Name : "+name+" Age : "+age) # Here We did not change age into the string using str function, because we take age input as a string type.
At Last Thanks for Reading...
If you have question or doubt about this post don't forget to leave a comment in a Comment Box. and Don't be Cheap to share with others if you like it.
Previous Topic : Part 2. Next Topic : String Formatting.
If you want to learn Python from Zero to Hero, You are on the right place to learn Python, This Blog will help you to learn Python from Zero to Hero, Let's make learning fun with your smiley face.
So This is the third part of Python Tutorial, If you want to read Part1 or Part2 click the links below.
Learn Python from Zero to Hero Part 1
Learn Python from Zero to Hero Part 2
Variables in Python :
If you read little bit about Python than you know about it, that is Python does not support variable type, This make Python easy, You don't have to be confused about the variable types, OMG! which type of variable should i use there ?, Oh! No, I have again made a variable type mistake in my code Oh Shit!, But now you will not going to get any kind of variables error in your code, what i am talking about. Because Python gives you the freedom to #CodeYourself, So let's See How Python use variables ?.
# Variables in Python.
num = 2print(num)
name = "Syntaxios Blog"
print(name)
Multiple Variables :
# Multiple Variable Initialization.
name, age = "Syntaxios", "2017"print("Name : "+name+" Age : "+age)
*NOTE : There are few rules about the variables type, that you must have to keep in mind, that is Variable Name should not be start with any number or special character, Python's variable does not support any special character so please avoid the special character in your variable, as we all coder know it's very complicated to assign a meaning variable name #Hahaha, I personally advice you to use camelCase or snake_case writing for variable name.
for Example :
1num = 2 (Wrong)
num1 = 2 (Right)
_num = 2 (Right)
$num = 2 (Wrong)
for Example :
1num = 2 (Wrong)
num1 = 2 (Right)
_num = 2 (Right)
$num = 2 (Wrong)
You can update your Integer variable at any time, But you can not update String in Python, Because Strings are immutable in Python.
If you want to build Niche Website Templates : click here to Choose best Niche Templates for your business.
String Concatenation in Python :
String concatenation is one of the important thing in programming world, Because this String Concatenation did a good job for programmers, String Concatenation is useful topic for programmers, We need this String Concatenation for make our program compatible. Let's See the Example.
# String Concatenation in Python.
first_name = "Syntaxios"last_name = "Be Syntaxios"
full_name = first_name + last_name # String Concatenation.
print("Name : "+full_name)
User Input in Python :
The most important things in each and every programming language the User Input, Sometimes if you want to learn more than a one programming language at the same time, you can learn the more than a one language at a time you should basically learn the basic concept of the programming which you want to learn like User Input, Loops, a little bit about variables etc. you should only focus on the basic concept the particular language. The User Input the most important one also, How to take Input from User in Python ?. Let's See How ?.
# How to take Input from User ?.
name = input("Enter Your Name ? ")print(" Hello : "+name) # String Concatenation.
Integer Input :
# How to take Integer type Input from User ?.
num_one = int ( input("Enter the First Number ? ") )num_two = int ( (input("Enter the Second Number ? ") )
add = num_one + num_two
print("Addition is : "+str(add)) # Here we change the Integer into the String using the str function. You can not concatenate Integer with String that by we change the Integer into the String.
Python always take input or count each and everything as a String, You can not perform string concatenation between the integer or string, String concatenation always perform between the string to string.
Float Input :
# How to take Float type Input from User ?.
num1 = float (input ("Enter float Number ? "))print(num1)
Multiple Input :
# Take Multiple Input in a single line.
first_name, last_name = input("Enter your full name ? ").split() # split means space.print("First Name : "+first_name+" Last Name : "+last_name)
or
name, age = input("Enter your name than coma than age ? ").split(",") # Here we take age as a String input not Integer.print("Name : "+name+" Age : "+age) # Here We did not change age into the string using str function, because we take age input as a string type.
If you want to build Niche Website Templates : click here to Choose best Niche Templates for your business.
At Last Thanks for Reading...
If you have question or doubt about this post don't forget to leave a comment in a Comment Box. and Don't be Cheap to share with others if you like it.
Previous Topic : Part 2. Next Topic : String Formatting.
Monday, December 17, 2018
Learn Python from Zero to Hero Part 2
December 17, 2018
This is the second part of Learn Python from Zero to Hero, If you want to read part 1 click here.
So Let's start...
Comment in Python :
Python use the # (Hash) for comment, Python does not support multi line comment like C, C++ or Java. If you want to make more than one line comment, you should have to use # for each line from the starting point.
Comment Example :
# This is a First Comment.
# This is the Second Comment.
print("Hello Wolrd!")
# This is the Second Comment.
print("Hello Wolrd!")
Escape Sequence in Python :
Escape Sequence is a sequence of character, that does not represent itself. Let's see the Example.
- \' - Single Quotes
- \'' - Double Quotes
- \\ - Backslash
- \n - New Line
- \t - Tab
- \b - Backspace
Escape Sequence Example :
# Escape Sequence Example.
print("Hello World!")
print(" \' : \'Single Quotes\'")
print(" \" : \"Double Quotes\"")
print(" \\ : \\Backslash\\")
print(" \n : \nNew Line")
print(" \t : Tab")
print(" \b : Backspace")
print("Hello World!")
print(" \' : \'Single Quotes\'")
print(" \" : \"Double Quotes\"")
print(" \\ : \\Backslash\\")
print(" \n : \nNew Line")
print(" \t : Tab")
print(" \b : Backspace")
Emoji in Python :
Did you know ?, You can print emoji's using Python, Python have the special feature that you can print Emoji's in Python.
Print Emoji's :
# Print Emoji's Using unicode in Python.
print("Emoji Code : \'\U0001F602\'")
print("\U0001F602")
print("Emoji Code : \'\U0001F602\'")
print("\U0001F602")
If you want more Emoji's Code Please click here, But remember one thing, When you visit the given link you will get the unicodes something like " U+1F602 " than you have to change this unicode to " \U0001F602 ". (For Example : U+1F603 to \U0001F603, U+1F607 to \U0001F607 etc.).
Calculation in Python :
Python also support almost same time of calculations like - + (Addition), - (Subtractions), / (Float Division) or % (Reminder), But wait a second Python have something extra for you, YES extra.
Python support two type of division that is a float division and the second one is integer division. yes Float Division and Integer Division.
Python have a little advance features, that makes Python AWESOME, Yes awesome, Python also support a special calculation method that is Exponent , Yes EXPONENT, Do you want to know ?. if No, Skip It, But If Yes so let's make your face smiley.
Exponent means something like 2³ that means 2*2*2 that is 8, You can use this exponent direct in Python. Use the ** for Exponent.
Calculation Example :
# Calculation using Python.
print("Addition 3+2 : "3+2)
print("Subtraction 3-2 : "3-2)
print("Float Division 5/2 : "5/2)
print("Integer Division 5//2 : "5//2)
print("Reminder 5%2 : "5%2)
print("Exponent 4³ : "4**3)
print("Addition 3+2 : "3+2)
print("Subtraction 3-2 : "3-2)
print("Float Division 5/2 : "5/2)
print("Integer Division 5//2 : "5//2)
print("Reminder 5%2 : "5%2)
print("Exponent 4³ : "4**3)
Previous Topic : Part 1 Next Topic : Variables in Python
Subscribe to:
Posts (Atom)