ভেরিয়েবল বা চলকঃ অন্যান্য প্রোগ্রামিং ল্যাংগুয়েজ এর মত পাইথনে ভেরিয়েবল ডিক্লেয়ার করতে হয় না। ভেরিয়েবল এ যে মান দেয়া হয় সেটার উপর ভিত্তি করে ভেরিয়েবল টাইপ নির্ধারিত হয়।
x=10 # Integer Variable assigned y=20.5 # Float Variable assigned s='Bangladesh' # String Variable assigned
তবে আমরা ভেরিয়েবল এর টাইপ বের করতে পারি
x = 10 y=4.5 s = 'Bangladesh' print(type(x)) # output: <type 'int'> print(type(y)) # output: <type 'float'> print(type(s)) # output: <type 'str'>
পাইথনে কমপ্লেক্স টাইপ ভেরিয়েবলও আছে
x = 2j y = -5j z = 10+2j # some example print(type(x)) # output: <type 'complex'> print(type(y)) # output: <type 'complex'> print(type(z)) # output: <type 'complex'>
তবে এক ভেরিয়েবলকে অন্য ভেরিয়েবলে রূপান্তর করা যায়। একে ভেরিয়েবল কাস্টিং বলা হয়।
x = int(10.2) # x will be 10 with integer type y = float(10) # y will be 10.0 with float type z = str(10) # z will be '10' with string type