Featured Post

SQL Interview Success: Unlocking the Top 5 Frequently Asked Queries

Image
 Here are the five top commonly asked SQL queries in the interviews. These you can expect in Data Analyst, or, Data Engineer interviews. Top SQL Queries for Interviews 01. Joins The commonly asked question pertains to providing two tables, determining the number of rows that will return on various join types, and the resultant. Table1 -------- id ---- 1 1 2 3 Table2 -------- id ---- 1 3 1 NULL Output ------- Inner join --------------- 5 rows will return The result will be: =============== 1  1 1   1 1   1 1    1 3    3 02. Substring and Concat Here, we need to write an SQL query to make the upper case of the first letter and the small case of the remaining letter. Table1 ------ ename ===== raJu venKat kRIshna Solution: ========== SELECT CONCAT(UPPER(SUBSTRING(name, 1, 1)), LOWER(SUBSTRING(name, 2))) AS capitalized_name FROM Table1; 03. Case statement SQL Query ========= SELECT Code1, Code2,      CASE         WHEN Code1 = 'A' AND Code2 = 'AA' THEN "A" | "A

Python Advanced For Loop With Example

Basically, For Loop reads input value and stores in a variable. So For Loop in Python needs two arguments. The two arguments are VARIABLE and IN. So far so good. The next part of the article and examples well explained how it works and how to get the index for each input supplied.

for loops in python

In Python, for loop list and count are related to the same logic. In the below example, I have taken one array and I counted using for loop, the number of elements in the input list.

For loop Syntax

for count in[1, 2, 3]: 
print(count)
print(’Yes’*count)

The first step, How the above syntax works are what I want to share with you. The 'in' represents input array for Python for loop. That means the for loop works 3 times in Python. It displays only 3 times. The third step is just to give 'yes', which will multiply with 'count' for 3 times.

This is the whole story of for loop in Python. In the second step, print just displays values of input that stored in the for loop variable of 'count'.

The 'count' gets values one by one from for loop input array. When you used the Shell to enter a loop, there was a reason that the interpreter waited to respond until after you entered an empty line: The interpreter did not know how long the loop block was going to be! The empty line is a signal to the interpreter that you are done with the loop block.

The index in For loop 

A small example is given to get index and value from for loop.
#Get index using for loop
#You will get index and value
mylist=[1, 2, 3]: 
for idx, val in enumerate(mylist):
    print(idx, val)

Video Tutorial

I have created a small video so that you can play quickly and check how for loop works in Python.
Also, read

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

Explained Ideal Structure of Python Class

How to Check Kafka Available Brokers