How Use Code For On Python

Tanggal : 13 Feb 2023, Category : Tutorial, Create By : admin

The "for" loop in Python is used to iterate over a sequence (such as a list, tuple, or string) or other iterable object and execute a block of code repeatedly for each item in the sequence. Here's the basic syntax of a "for" loop in Python:

for item in sequence:
# Code to be executed for each item in the sequence

For example, to print the numbers from 1 to 10, you can use a "for" loop like this:

for i in range(1, 11):
print(i)

In this example, the variable "i" is used to represent each item in the sequence, which is created using the range() function. The code inside the loop is executed for each item in the sequence, and the value of "i" is updated accordingly.

You can also use a "for" loop to iterate over the elements of a list:

fruits = ['apple', 'banana', 'cherry']
for fruit in fruits:
print(fruit) 

In this example, the variable "fruit" is used to represent each item in the list "fruits". The code inside the loop is executed for each item in the list, and the value of "fruit" is updated accordingly.

 

 


Keyword:
  • How Use Code For On Python

Artikel Lain

Cara Menampilkan Dialog Konfirmasi Hapus Data Di Url Ahref Javascript

Date : 08 Sep 2018, Category : JavaScript, Create By : admin

Konfimasi adalah hal yang penting dalam pembuatan aplikasi, karena dengan konfirmasi pengguna bisa menastikan apakan langkah yang di ambil akan di lanjutkan di kerjakan atau tidak, seperti contohnya dalam menghapys .....

What Is Css Language And Examples Of Its Use

Date : 13 Feb 2023, Category : CSS, Create By : admin

CSS (Cascading Style Sheets) is a style sheet language used for describing the look and formatting of a document written in HTML or XML. It is used to control the .....

Mengenal Fungsi Break Dan Continue Javascript

Date : 28 Dec 2018, Category : JavaScript, Create By : admin

Dalam bahasa pemprograman javascript kita bisa menggunakan fungsi Break dan Continue, apa itu Break dalam bahasa indonesia bisa di artikan istirahat, yaitu menghentikan sebuah looping, Sedangkan Continue artinya  terus atau berlanjut, sebenarnya fungsi Continue .....