PermalinkIntroduction
Now things are slowly scaling up. On day 5, I learned about comments, escape sequence characters and some parameters of print statements. In today's blog, I will share more details on my learnings from Day 5 coding journey.
So let's get started......
PermalinkCOMMENTS
Comments. Highlighted parts give errors. Invalid syntax
A comment is that part of the code which the interpreter or the compiler ignores while running the code. The Programmer writes certain code that he does not wish to execute. Usually, comments are written to either explain certain blocks of code or to avoid the execution of specific parts of code while testing.
There are 2 types of comment statements -
Single line comment
Multi-line comment
PermalinkSingle Line Comments
To write single-line comments just add a '#' at the start of line.
#This is a 'Single-Line Comment' This line will not get printed
print("This is a print statement.")
print("Hello World !!!") #Printing Hello World - Code after '#' will not get printed
PermalinkMulti-line Comments
To write multi-line comments there are 2 ways
Either add '#' at the start of each line
Or you can use ''' ..... ''' , triple quotes
Check out the below example
Example 1: The use of '#'
#It will execute a block of code if a specified condition is true.
#If the condition is false then it will execute another block of code.
p = 7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
Output
p is greater than 5.
Example 2: Use of multiline string i.e '''....'''
"""This is an if-else statement.
It will execute a block of code if a specified condition is true.
If the condition is false then it will execute another block of code."""
p = 7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
Output
p is greater than 5.
PermalinkEscape Sequence Characters
Something we face an issue to write certain characters in a string and hence we make use of Escape Sequence Characters.
An escape sequence character is written by a backslash " \ " followed by a character you want to insert.
For example
"\n" \>>> this takes you to the new line of code
Example -
print("This doesnt "execute") #this line gives error
print("This will \" execute")
Example -
print("Hi, this is chintan and \nI am learning PYTHON. \nYou can also follow along my journey") #Note how \n takes the program output on new line
Output
Hi, this is chintan and
I am learning PYTHON.
You can also follow along my journey
Permalinkprint() Statements Parameters
I learned more about print() statements using 4 parameters viz, objects, sep, end and file operator in print().
object(s): An object will be converted to a string before printed
sep='separator': Specify how to separate the objects, if there is more than one. default is ' '
end='end': It specifies what to print at the end. Default is '\n' (line feed)
file: An object with a write method. default is sys.stdout
Example -
print("Hey", 5, 7, sep='~', end="009")
print("harry") #this print on same line as above because no "\n" used
Output
Hey~5~7009harry
PermalinkResources Used
PermalinkConclusion
Thanks, guys for going through this blog post. Slowly upscaling myself and sharing my coding journey on the way. I am 100% sure, if someone reads this article many might find it common, but as a beginner, learning new things in coding is awesome.
I hope someone finds this article useful.
So this is it for the BLOG post and Day #5 of Python.
See you in the next one.....
PermalinkAbout Me
Hey Guys, I am Chintan Jain from CodeWithJain. I am a trader and content creator. I am also passionate about tech and hence wanted to explore the field of tech. I always wanted to learn to code so I watched many tutorials but procrastinated practicing coding. To get into the habit of coding consistently I am starting to BLOG with HASHNODE on daily basis.
I will document my coding journey from scratch and share my daily learnings in a blog post on HASHNODE. I hope you all will enjoy my content and my coding journey.
So what are you waiting for, smash the FOLLOW and LIKE buttons and follow along my coding journey, a step to create more beautiful digital products and empower people.
GitHub - github.com/CodeWithJain
Twitter - twitter.com/CodewithJain
Instagram - instagram.com/codewithjain
Youtube - youtube.com/@CodeWithCJ