Python Dhata Dhata uye Type Shanduko

Sumo pane Python dhata mhando uye maitiro ekuita mhando kutendeuka.

Python Dhata Dhata

Patinogadzira kana kuzivisa akasiyana muPython, misiyano inogona kubata mhando dzakasiyana dzedata.

Python ine inotevera yakavakirwa-mukati mhando dze data:

  • p
  • int, ichiyangarara, chakaoma
  • list, Tukiro
  • raira
  • set
  • bool
  • byte, chemirizi

Rudzi rwemavara: str

I str mhando yedata inoshandiswa kana tichida kuzivisa a tambo kusiyanisa.

Muenzaniso:

x = 'some string' y = str('another string')

Nhamba yeNhamba: int, ichiyangarara, yakaoma

Kana tichida kugadzira akasiyana manhamba isu tinoshandisa int, float kana complex.



Muenzaniso:

//int a = 5 b = int(5) //float c = 5.5 d = float(5.5) //complex e = 1j f = complex(1j)

Nhevedzano Type: runyorwa, Tuple

Kugadzira akateedzana mhando misiyano yatinoshandisa list kana tuple.

  • A list iunganidzwa inorayirwa uye inochinjika. Inotendera zvakapetwa nhengo.
  • A tuple muunganidzwa wakarairwa uye usingachinjiki. Inotendera zvakapetwa nhengo.

Muenzaniso:

//list colors = ['red', 'green', 'blue'] colors_list = list(('red', 'green', 'blue')) //tuple fruits = ('apple', 'orange', 'banana') fruits_tuple = list(('apple', 'orange', 'banana'))

Mepu Rudzi: dict

Kugadzira mepu kana duramazwi tinoshandisa dict.

TO Duramazwi iunganidzwa isina unordered, inochinjika uye yakanyorwa. Iyo data yakakosha kukosha mapara.

Muenzaniso:

people = {'name': 'John', 'age': '45'} people_dict = dict(name='John', age=45)

Set Rudzi: set

A set iunganidzwa isina unordered uye isina kunyoreswa.

Kugadzira seti, tinoshandisa set.

Muenzaniso:

status_codes = {'200', '300', '400', '500'} status_codes = set(('200', '300', '400', '500'))

Boolean Rudzi: bool

I bool keyword inoshandiswa kugadzira misiyano ine boolean dhata mhando.

is_valid = False valid = bool(is_valid)

Binary Rudzi: byte, bytearray

Binary data mhando dzinogona kugadzirwa seinotevera:

//bytes a = b'some_text' b = bytes(5) //bytearray c = bytearray(3)

Ungawana sei Rudzi rweMusiyano

Kuti tiwane mhando yeshanduko tinoputira musiyano mukati me type() basa.

Semuyenzaniso:

colors = ['red', 'green', 'blue'] colors_list = list(('red', 'green', 'blue')) print(type(colors_list)) print(colors_list) fruits = ('apple', 'orange', 'banana') fruits_tuple = tuple(('apple', 'orange', 'banana')) print(type(fruits_tuple)) print(fruits_tuple)

Kubuda:

['red', 'green', 'blue'] ('apple', 'orange', 'banana')

Python Dhata Rudzi Kutendeuka

Python inotsanangura mhando yekushandurwa kwemabasa kushandura yakananga imwe data dhata kuenda kune imwe, izvo zvinobatsira kwazvo.

Pazasi pane mimwe mienzaniso:

Chinja Kubva int kuenda kuyangarara

x = 5 y = float(x) print(y)

Kubuda:

5.0

Chinja Kubva ku float kuenda int

x = 5.0 y = int(x) print(y)

Kubuda:

5

Chinja Kubva pane tambo kunyorera

s = 'devqa' t = list(s) print(t)

Kubuda:

['d', 'e', 'v', 'q', 'a']

Chinja Kubva patambo kuenda kuTuple

s = 'devqa' t = tuple(s) print(t)

Kubuda:

('d', 'e', 'v', 'q', 'a')

Chinja Kubva tambo kuisa

s = 'devqa' t = set(s) print(t)

Kubuda:

{'d', 'e', 'a', 'v', 'q'}