Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

I'm new here and furthermore new to Python. I was wondering about what does f in print(f'Column names are {"- ".join(row)}') do I had a go at erasing it and afterward 'Section names are {"- ".join(row)}' become an ordinary string 

Could you please help me with what does f called, so I can google it to study it? Thank you in advance

import csv

with open('CSV_test.txt') as csv_file: 

    csv_reader = csv.reader(csv_file, delimiter=',')

    line_count = 0

    for row in csv_reader:

        if line_count == 0:

            print(f'Column names are {"-".join(row)}')

            line_count += 1

        else:

            print(f'\t{row[0]} works in the {row[1]} '

                  f'department, and was born in {row[2]}.')

            line_count += 1

    print(f'Processed {line_count} lines.')

1 Answer

0 votes
by (26.4k points)

The join method restores a string where the elements of the arrangement have been joined by a separator. In your program, it takes a row list and joins then by separator -

At that point by utilizing the f-string, the expression determined by {} will be supplanted with its value. 

Assume that line (row) = ["1", "2", "3"] then the output will be Column names are 1-2-3.

Join the python online course fast, to learn python concepts in detail and get certified.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Nov 21, 2020 in Python by sandy (120 points)
+1 vote
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...