MulaiMulai sekarang secara gratis

Assignment and data types

This exercise covers assigning values to variables and the basic data types in Python. Recall that unlike R, Python has only one way to assign values, by using the = sign. To assign the string hello to the variable x you would write:

x = 'hello'

A quick refresher of the data types in Python:

  • int (integers): numbers without a decimal
  • float (floating point numbers): numbers with a decimal
  • bool (booleans): True or False values
  • str (strings): usually to represent text. However, anything that is wrapped in quotes (single or double) is treated as a string.

You can determine the data type of an object by using the type() function. For example, if you want to determine the data type of x, you can use:

print(type(x))

<class 'str'>

Latihan ini adalah bagian dari kursus

Python for R Users

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Assign an integer (42) to w
____ = ____

# Assign a float (3.14) to x
____ = ____
Edit dan Jalankan Kode