Skip to main content

Command Palette

Search for a command to run...

Python :- The Start

Published
5 min readView as Markdown

Hi there , Mandeep this side !

Today I am gonna share with you , what I have learned from the Today’s class …

First I thought of creating something very banger than I realized that for this easy stuffs and starting bits I will avoid wasting your time , because time matters.

So i wrote a short notes on today’s class so you can refer them , we will discuss things in future when things worth taking time . But for now let ‘s head into a small recap …

Python

print( ) :- print() function in python

We use it to display the data given by the user. For an example

print("Hello World")

this print function contains three params “file” , “sep” , “end” : for now we will discuss ‘sep’ and ‘end’.

  1. end :- This parameter ask you to enter a string / character that you want to get print after the whole print data in the print function. for example

     print("Hello",end = " ")
     print("World")
     #OUTPUT :- Hello World
    
  2. sep :- Now what this parameter do . Hmm , as the name suggest that sep means seprator , when you assign some character or string to this “sep” param it will seperate the string by that , for example :-

     print("Apple","Banana","Orange",sep = ",")
     #OUTPUT :- Apple , Banana , Orange
    

input() function :- Input function of python

this function is very straight forward it is use to take input from the user , also in this input function we can send a string value which act as a placeholder for the user to indicate user what you are expecting in this block.

user_input = input("Enter your name :") # => Mandeep
#we can display them as well
print("Hey my name is " + user_input) # => Hey my name is Mandeep

Now lets try to update the variable ,

user_input = "Amandeep" 
print("Hey name is " + user_input) # => Hey my name is Amandeep

Why the DATA is changed ???? Where the old data gone now ???

What happen is when you create a variable and assign the data to it , then that data is stored in an object internally in python and that variable name will start pointing to it , now if you assign any Value to that same variable then that variable will point to this new object not that the old one , and that old one will erased by garbage collector.

How Garbage collector triggers??

Heap memory have threshold that if 70%(some value) of my heap memory is used then garbage collector come and clear the objects that don't have any variable assign to it.

Now in short all of the objects get cleared which don’t have variable pointing them…

Comments :- Everyone remembers them but but let see once…

  1. We use ‘#’ to write a single line comment , example down here …
# This is a Single Line comment
print("Added the single Line comment")
  1. We use ‘‘‘ ‘‘‘ group of 3 - 3 single quotes to write multiline comment , example like always down here
'''
This is a MultiLine comment
That iam using here
We will do to acheive higher infomation display
'''
print("Added multiline comment")

INDENTATION :- Facility in python which works as code block seperator.

We use indentation in python to seperate some code from some code , Ahh okay think like this that you have to write some code under the influence of above written code then you use this INDENTATION to seperate them which make python understand that this indented code will run only if this above one triggers.

For better understanding see this example :-

x = 5
if x > 3:
    print("X is greater than 3")

Here , We write a If block of code and then print statement using indentation which suggest that if the “if” block executes properly then only you should run the “under written” or “under influenced line” .

** Unpopular Opinion but I like Curly braces more this is confusing yaar **

Variables : - I will not waste time here just straight forward rules that you have to follow

So while Creating Variables there are some written and unwritten rules that you should follow .

  1. Written :- Let first see the Written one which are imposed by python.

    how to name a variable ? The naming of the variable should be senseful which help you to do define your code in best way not the leasure that you can use.

    Legal Variable Name :- Rules by python on variable naming ,

    1. Letter (a-z , A-Z)

    2. digits (0-9)

    3. Underscore

but remember your variable should always start with a letter.

Case Sensitivity :- In python there is case sensitivity for variables because "a" and "A" is considered as different.

  1. UnWritten : - Yaa it’s unwritten but never name variable like ‘a’ ,’b’ , etc like this means useless nomenclature that you follow pls don’t do this , So what to do ??

    You should put their name sensible like “userData” , “knownData”, “rawData” etc ..

  2. KEYWORDS :- The reserved words like input , print , for , if , else This are keywords in python you can't make them variables . So this is rule yaa sure try to create one you will slamed by python , sorry but yes it is true , So try to avoid them

    And you will come to Know soon which are keywords in python.

DATATYPES :- Nature of Variables

Now we have created a lot of variables but who will decide their datatypes , for you Python do that internally , yaa you are free to create variable and use them .. :)))

for example :- Let us create multiple variable and check their types

integer_val = 2
complex_val = 2 - 5j
string_val = "This is string"
float_val = 3.14

type(integer_val)
type(complex_val)
type(string_val)
type(float_val)

Thank you : )

Yaa thanks for being with me till here , I invested a lot of time by writing this myself so just like it or make comment , and if there is any thing that i wrote wrong pls tell me in comment or discord I will edit that . I have written more blogs before you can explore if you need an upper hand in python ……..

Bye Bye : )

More from this blog

Data Science

6 posts

Here , I am documenting my journey of Learning Data Science.