DEV Community

30 Days of Python πŸ‘¨β€πŸ’» - Day 2 - Data Types I

Arindam Dawn on June 22, 2020

Before diving deep into the nitty-gritty details of a programming language or perhaps even a human language, we need to understand its terminologie...
Collapse
 
mowat27 profile image
Adrian Mowat

One thing I found strange about strings in Python is that there doesn’t seem to be much of a material difference between using single and double quotes. In other languages, string interpolation only works inside doubles and singles are treated as exact literals but strong formatting in python works differently (as I’m sure you’ll find soon). The only time I can see a need to choose one over the other is when you have quotes inside your strings. Maybe someone can correct me on this or point out the relevant idiom. Still, keep up the good work man. I waited to long to invest time in learning Python and I have to say it’s been a real joy since I started a few months ago.

Collapse
 
arindamdawn profile image
Arindam Dawn

After reading some articles and blog posts I found out that:

  • %-format method is a very old method for interpolation and is not recommended to use as it decreases the code readability.
  • In str.format() method we pass the string object to the format() function for string interpolation.
  • In the template method, we make a template by importing template class from built-in string module.
  • Literal String Interpolation method is powerful interpolation method which is easy to use and increase the code readability.

I am still figuring out the best practices but I personally like the f syntax.

And yes learning python is a real joy. Hope I keep getting better at it :) Thanks for reading the blog.

Collapse
 
mowat27 profile image
Adrian Mowat

Yeah me too. f'{}...' usually meets my needs and I only use format when I need to use printf style formatting or the expression I want to print is complex enough to impact readability inside a simple interpolation.

I believe the %-format approach is from python2 and str.format() is preferred in python3. You still see it a lot though.

Collapse
 
fadykhallaf profile image
Fady khallaf

"Variables must start with a lowercase letter" can you edit this line because Python variables can start with uppercase letters as well. the variable in python must start with a letter or underscore (letter can be a capital uppercase or lowercase), it can't start with a number or special character.

Collapse
 
arindamdawn profile image
Arindam Dawn

Thanks for your observation. I have now updated the line.

Collapse
 
fadykhallaf profile image
Fady khallaf

You're welcome.

Collapse
 
pipistrel0 profile image
Pipistrel0

Nice man, keep it going with this I'm enjoying this and learning with you.

Collapse
 
arindamdawn profile image
Arindam Dawn

I am glad you liked it 😊

Collapse
 
samir737 profile image
samir737

So glad to follow you and learning from you

Collapse
 
arindamdawn profile image
Arindam Dawn

I am glad 😊

Collapse
 
codemonsterlab profile image
codemonster-lab

Too good man....

Collapse
 
pvmahida profile image
PVMahida

Thank you very much for this, enjoying and learning this with you.

Collapse
 
arindamdawn profile image
Arindam Dawn

So glad to hear that :)

Collapse
 
krispern profile image
krispern

"Keywords should not overwrite keywords" I'm assuming you meant "Variables should not overwrite keywords"