isspace(): checking white space only in a string in Python

Use the isspace() method to check if the characters in a string are all white spaces. text = ' ' print(text.isspace()) #output: True text = ' \f\n\r\t\v' print(text.isspace()) #output: True text = ' ' print(text.isspace()) #output: True text = ''…

isidentifier(): checking a valid identifier in Python

Use the isidentifier() method to check a valid identifier. A valid identifier has only letters, digits, and underscores. text = 'file1' print(text.isidentifier()) #output: True text = '1file' print(text.isidentifier()) #output: False text = 'file1_final' print(text.isidentifier()) #output: True text = 'file1 final'…

isalnum(): checking alphanumeric only in a string in Python

Use the isalnum() method to check if a string only contains alphanumeric characters. word = 'beach' print(word.isalnum()) #output: True word = '32' print(word.isalnum()) #output: True word = 'number32' #notice there is no space print(word.isalnum()) #output: True word = 'Favorite number…

ljust(): left-justified string in Python

Use the ljust() to left-justify a string. word = 'beach' number_spaces = 32 word_justified = word.ljust(number_spaces) print(word) #'beach' print(word_justified) #'beach ' Notice the spaces in the second string. The word ‘beach’ has 5 characters, which gives us 27 spaces to…

rjust(): right-justified string in Python

Use the rjust() to right-justify a string. word = 'beach' number_spaces = 32 word_justified = word.rjust(number_spaces) print(word) #'beach' print(word_justified) #' beach' Notice the spaces in the second string. The word ‘beach’ has 5 characters, which gives us 27 spaces to…

Organizing Files in Python

This article covers operations you can do with a file regarding the Operating System: rename and move a file, check if a file exists, delete a file, make a copy of a file. This a direct extension of a previous…

Deliberate Practice and the Senior Developer

The most common measure used to tell the level of seniority of a developer is years of experience. I couldn’t disagree more. If you are working on the same project, with the same technologies for the last 6 years, chances…

While Loops in Python

Loops are used when you need to repeat a block of code a certain number of times or apply the same logic over each item in a collection. There are two types of loops: for and while. In this article,…