STAY WITH US

4. [Hindi]Machine Learning : Input() Function & Escape Characters | 2018


           

Input() Function & Escape Characters



4. [Hindi]Machine Learning : Input() Function & Escape Characters | 2018

       Good morning guys!!!. Welcome back to another tutorial. Recently i have started this blog series specially for you guys. So, that you guys can enjoy machine learning series. I am also preparing video tutorial series, if you want you guys can first follow the video tutorial then you can come on to this document for the detailed reading. 

                  In this blog, i am going to discuss about Input() function in Python. Remember, we are using Python 3. Sadly, Python 2 is no longer alive. It's a dead series. Input() function is used to take runtime inputs to python program or we can give standard input to python script. In Python, for standard input we have a simple function to do this task. In order to use this function, first you have to take care about the syntax of the function, which is mention below,

 Syntax :   Var_name = input("Enter the Value")

   that's all it is, if you talk about me i simply like the simplicity of the function. When you use this function, by default it provides you string output. let' s take an example,

greeting = 'Hello'
name = input("Enter the name : ")
print(greeting+' '+name)
Enter the name : vishwajeet 
Hello vishwajeet  

    As you can see, we are simply taking input with the help of Input function in the form of string.

   In the next example, we are going to see that how to use Input() function to take integer input. So, we know that we cannot take integer input directly from the function. So in that case, we have the typecast the input value. example as mention below :      

var1 = int(input("Enter the value : "))
var1
type(var1)
Enter the value : 1234

Out[5]: int

      Let's take another example, you can also use input function to replicate string values with the help of multiplication operator. In python it is very easy to replicate values,

var1 = input("Enter the value")
var1 = var1 * 2
print(var1)
Enter the value knowledge SHelf 
knowledge SHelfknowledge SHelf   

      You can also split string with the help of "\n" also know as newline character. let's understand this with the help of example, 

splitString = "Mera name vishwajeets hai,\nor mai youtube par \nvideos banata hu."
print(splitString)
Mera name vishwajeets hai,
or mai youtube par 
videos banata hu.

    In the above mention example, we are using "\n" character to start the string from the next line. Hope you are getting it. Ok let's move on.

     In the next section, we will "\t" character for providing Tab Space in the output. Let's check out this line of code,

tabString = "1\t2\t3\t4\t5\t"
tabString1 = "1 2 3 4 5"
print(tabString)
print(tabString1)
1 2 3 4 5 
1 2 3 4 5

     As you can see, this code is showing the classic example of how you can use Tab Space or "\t" operator.

    At the end of the blog i am going to show you few more examples of Python with print function.

print('what\'s your name?')
print("Mera name \"vishwajeet\" hai")
what's your name?
Mera name "vishwajeet" hai
print('Mera name vishwajeets hai,or mai youtube par videos banata hu.')
print("Mera name vishwajeets hai,or mai youtube par videos banata hu.")
print("What's your name?")
print('''Mera name vishwajeets hai,
or mai youtube par 
videos banata hu.''')
Mera name vishwajeets hai,or mai youtube par videos banata hu.
Mera name vishwajeets hai,or mai youtube par videos banata hu.
What's your name?
Mera name vishwajeets hai,
or mai youtube par 
videos banata hu.
      At last these these are few more examples from my side to finish this blog. Guys please do lot's of practice to improve your programming and at the end. 

Enjoy Programming!!!!!!!!!!!

Post a Comment

0 Comments