Learn to Code via Tutorials on Repl.it!

← Back to all posts
Python Basics TUTORIAL 2.. 😎😎
h
SUHASTADIPARTH1 (174)

Hey guys, today I will be covering data types and math

Few data types

  • integers
  • strings
  • boolean
  • lists

This is how you declare in int(integer)

num = 2 # this num variable stores a number

Strings

word = "Python" # this is how you declare a string (add quotes. Can be single or double)

Boolean

is_male = True # capitalize the T

lists

nums = [1, 2, 3, 4, 5] # a list can contain multiple values unlike a variable which can only contain one value

# a list can contain different data types, so you can do this

values = ["Python", 1, True, False, 2, "car"]

Math in Python

print(2 + 2) # this will output 4 to the console

You can use these to do basic math

  • +
  • -
  • *
  • /
  • %
print(2 - 2) # outputs 0 to the console
print(2 * 2) # outputs 4 to the console
print(10 / 5) # outputs 2  to the console
print(2 % 2) # % (modulus) operator outputs the remainder, so in this case 0
Commentshotnewtop
Wumi4 (453)

There are also a // too, which do the same as / but return a integer instead of float ( as my brain said ).

SUHASTADIPARTH1 (174)

@Wumi4 Yes, I know that. But I wanted to cover the basics, not advanced.

SUHASTADIPARTH1 (174)

@Bookie0 oh, i thought they were a bit advanced. I wanted cover the most basic operators.

Bookie0 (4983)

@SUHASTADIPARTH1 almost every tutorial covers them

SUHASTADIPARTH1 (174)

@Bookie0 well, ok. I will do that next time.

CodeLongAndPros (1535)

@SUHASTADIPARTH1 And modulo is basic? Anyways, you can emulate // by doing int(x /y) or int(str( x /y).split('.)[0)

SUHASTADIPARTH1 (174)

@CodeLongAndPros That is true. I think I am going to make a tutorial on this. Using the advanced operators.

CodeLongAndPros (1535)

@SUHASTADIPARTH1 You gave a tutorial on creating variables and doing math, and you call that complete?

SUHASTADIPARTH1 (174)

@CodeLongAndPros No, I have a tutorial series. And this is the second tutorial in the series. I have more tutorials coming up.

Kookiez (305)

@SUHASTADIPARTH1 but if it's a series then it would probably be called cycle squeezing

Kookiez (305)

@SUHASTADIPARTH1 well, at least most people would, if it's a really long part 1 and a long part 2, i wouldn't call that cycle squeezing. but this is really short, i would really recommend to make it one long tutorial or 2 long tutorials.

Bookie0 (4983)

btw think u messed up the markdown a bit here

you should also try to concatenate all your tutorials together instead of making a whole small series like these, and make them a bit longer too :)

SUHASTADIPARTH1 (174)

@Bookie0 yes, I was just covering the basics. Not advanced stuff. But thanks for the feedback.

Bookie0 (4983)

@SUHASTADIPARTH1 yea, but you can join all the "basic" tutorials together

SUHASTADIPARTH1 (174)

@Bookie0 ok. I will do that next time.