🚧Summaries For Lessons 24+ Are Still Work In Progress!

“Whoever is patient has great understanding…" Proverbs 14:29

Basic Data-Types In Python

Description here...

Basic Data-Types In Python

Description here...

Basic Data-Types In Python

Description here...

  • Syntax: Python Rules

  • Basic Data-Types

  • How to Store data in Variables

  • Exercise: Simple Text Formatting

What is Syntax?

We're ready to begin coding, however before we begin you need to understand that there are certain rules in Python on how to write and structure your code so it can be executed correctly. And these rules are called - Syntax.

Syntax - is like a grammar of programming languages. And if you don't follow it, then Python won't understand you and you'll get an error.

But don't worry - Errors are you best teachers. They'll let you know exactly where and what went wrong so you can go and fix it. And hopefully learn along the way.

Python be like when you get an error:

Kidding, it's much friendlier.

Basic Data-Type: Strings

Let's begin exploring syntax rules with String Data-Type, which refers to text.

To create strings we need to use 'single' or "double quotes" on each side of the message. That's a syntax rule for strings.

'Text in python is called String'
"It has to be inside single or double quotes"
'We can use "double-quotes" inside single quotes'
"And 'vice-versa' " # This is a string
'Text in python is called String'
"It has to be inside single or double quotes"
'We can use "double-quotes" inside single quotes'
"And 'vice-versa' " # This is a string
'Text in python is called String'
"It has to be inside single or double quotes"
'We can use "double-quotes" inside single quotes'
"And 'vice-versa' " # This is a string

⚠️However, keep in mind we can't write text without quotes. This will break python syntax rules, and it will certainly lead to many errors.

Also notice that certain words are highlighted (not, in, break).
There are certain keywords in Python with a special meaning to create Logical Statements, Loops, Functions and use other concepts (More on that later...).

# Comments in Python

While coding you might leave some remarks of a piece of code that should be ignored by Python. And we can use Comments for that.

To create a comment put # symbol and then python will ignore everything on the right side of it. You can even put comments after your statements:

"And 'vice-versa' " # This is a string

# But we can not write text in python without quotes.
# It will break syntax rules...
"And 'vice-versa' " # This is a string

# But we can not write text in python without quotes.
# It will break syntax rules...
"And 'vice-versa' " # This is a string

# But we can not write text in python without quotes.
# It will break syntax rules...

As a beginner use comments to document your code and explain what's going on. No need to write an essay, but it's great to leave quick comments everything.

It's very common for beginners to write code, and then come back a few days/weeks later and forget what's going on. Comments can remind you most important parts. So leave comments to help your future-self or at least organize your code to be more readable.

Variables: How to Store Data?

In python you can't write your data anywhere you want. You need to assign your data to containers called 'Variables'. Think of it as a box that can store your data (text, numbers, lists...)

It's needed so you can define your data once and then reuse it many times in your code, always referring to the same data. You can also override the data if you need to.

To create a variable write a single word (without quotes) and then assign data with = equal sign. Later you can use the same variable name to access this data.

For example, you can print the data that variables hold like this:

#📦 Text Variables
#--------------------------------------------------
text   = 'Text in python is called String'
text_2 = "It has to be inside single or double quotes"
text_3 = 'We can use "double-quotes" inside single quotes'
text_4 = "And 'vice-versa' " # This is a string

#👀 Print Statements
#--------------------------------------------------
print(text)
print(text_2)
print(text_3)
print(text_3)
#📦 Text Variables
#--------------------------------------------------
text   = 'Text in python is called String'
text_2 = "It has to be inside single or double quotes"
text_3 = 'We can use "double-quotes" inside single quotes'
text_4 = "And 'vice-versa' " # This is a string

#👀 Print Statements
#--------------------------------------------------
print(text)
print(text_2)
print(text_3)
print(text_3)
#📦 Text Variables
#--------------------------------------------------
text   = 'Text in python is called String'
text_2 = "It has to be inside single or double quotes"
text_3 = 'We can use "double-quotes" inside single quotes'
text_4 = "And 'vice-versa' " # This is a string

#👀 Print Statements
#--------------------------------------------------
print(text)
print(text_2)
print(text_3)
print(text_3)

P.S.
Make sure you don't use variable names with internal meaning in Python. This will override this meaning and you can break your Python. You might not know all the names yet, but you'll learn them as you progress during this course.

All Basic DataTypes

# Basic Data-Types in Python
#--------------------------------------------------
string    = 'text'
num_int   = 10
num_float = 3.14
boolean   = True #False
none_type = None
# Basic Data-Types in Python
#--------------------------------------------------
string    = 'text'
num_int   = 10
num_float = 3.14
boolean   = True #False
none_type = None
# Basic Data-Types in Python
#--------------------------------------------------
string    = 'text'
num_int   = 10
num_float = 3.14
boolean   = True #False
none_type = None

As you can see they are very simple. These are the building blocks for any script logic you'll want to create.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Check Variable Types

As you code sometimes you might need to verify the type of your variables. And for that we can use type() built-in function. You can provide any object and it will return its type.

So to display in the console we also need to print() it, and here's how to combine both of them:

print(type(string))      # <class 'str'>
print(type(num_int))     # <class 'int'>
print(type(num_float))   # <class 'float'>
print(type(boolean))     # <class 'bool'>
print(type(none_type))   # <class 'NoneType'>
print(type(string))      # <class 'str'>
print(type(num_int))     # <class 'int'>
print(type(num_float))   # <class 'float'>
print(type(boolean))     # <class 'bool'>
print(type(none_type))   # <class 'NoneType'>
print(type(string))      # <class 'str'>
print(type(num_int))     # <class 'int'>
print(type(num_float))   # <class 'float'>
print(type(boolean))     # <class 'bool'>
print(type(none_type))   # <class 'NoneType'>

Usually you'd do that during development, and then you'd comment it out once your code is complete.

Simple Exercise

Lastly, let's have an example of how we could use variables to make our life easier.

Imagine you have a simple story:

print('Once upon a time, there was a Revit User named Erik')
print('Erik has spent months on soul-draining tasks in Revit')
print('Until one day Erik said: Enough!')
print('And by accident he discovered that he could automate his Revit work with python')
print('But Erik knew nothing about python.')
print('And so, Erik has begun his programming journey.')
print('Once upon a time, there was a Revit User named Erik')
print('Erik has spent months on soul-draining tasks in Revit')
print('Until one day Erik said: Enough!')
print('And by accident he discovered that he could automate his Revit work with python')
print('But Erik knew nothing about python.')
print('And so, Erik has begun his programming journey.')
print('Once upon a time, there was a Revit User named Erik')
print('Erik has spent months on soul-draining tasks in Revit')
print('Until one day Erik said: Enough!')
print('And by accident he discovered that he could automate his Revit work with python')
print('But Erik knew nothing about python.')
print('And so, Erik has begun his programming journey.')

Now you decide to change user name and the app. But doing it manually is prone to errors and not very efficient...

So instead, define variables once, and then use them inside your print statements. And if you decide to change the name or app, you have to make change only in one place. And to do that you can join multiple pieces of text including your variables.

Like this:

# 💪 Simple Excercise
#--------------------------------------------------
user = 'Klaus'
app  = 'Photoshop'

print('Once upon a time, there was a' + app + 'User named ' + user)
print(user + ' wasted months on soul-draining tasks in ' + app )
print('Until one day' + user + ' said: Enough!')
print('And by accident he discovered that he could automate his' + app +  ' work with python')
print('But ' + user + ' knew nothing about python.')
print('And so, ' + user + ' has begun his programming journey.')
# 💪 Simple Excercise
#--------------------------------------------------
user = 'Klaus'
app  = 'Photoshop'

print('Once upon a time, there was a' + app + 'User named ' + user)
print(user + ' wasted months on soul-draining tasks in ' + app )
print('Until one day' + user + ' said: Enough!')
print('And by accident he discovered that he could automate his' + app +  ' work with python')
print('But ' + user + ' knew nothing about python.')
print('And so, ' + user + ' has begun his programming journey.')
# 💪 Simple Excercise
#--------------------------------------------------
user = 'Klaus'
app  = 'Photoshop'

print('Once upon a time, there was a' + app + 'User named ' + user)
print(user + ' wasted months on soul-draining tasks in ' + app )
print('Until one day' + user + ' said: Enough!')
print('And by accident he discovered that he could automate his' + app +  ' work with python')
print('But ' + user + ' knew nothing about python.')
print('And so, ' + user + ' has begun his programming journey.')

Now we're joining multiple strings into one using our variables. But we can agree on one thing:

🤬 It looks Horrible, isn't it?

It's fine to use + symbol to join strings on smaller examples, but in this case it's best to use string-formatting. Here's how.

String Formatting

Instead of joining strings one by one, we can use string-formatting.

It's a way to put placeholders {} inside your strings and then replace them with actual values. And there are 2 ways to do that, depending if you're on an old version of python or newer than 3.6.6+.

Here's an example of both options:

name = 'Erik'
age  = '29'

# After python 3.6.6 - f-string or .format()
print(f"My Name is {name} and I'm {age} years old")

# Before Python 3.6.6 - .format()
print("My Name is {} and I'm {} years old".format(name, age))
name = 'Erik'
age  = '29'

# After python 3.6.6 - f-string or .format()
print(f"My Name is {name} and I'm {age} years old")

# Before Python 3.6.6 - .format()
print("My Name is {} and I'm {} years old".format(name, age))
name = 'Erik'
age  = '29'

# After python 3.6.6 - f-string or .format()
print(f"My Name is {name} and I'm {age} years old")

# Before Python 3.6.6 - .format()
print("My Name is {} and I'm {} years old".format(name, age))

Both examples will produce the same result, but one is a bit simpler than the other. But notice how much simple and easier it is to insert your data in the middle on a sentence no w.

Now let's apply it to our story:

# 💪 Simple Excercise
#--------------------------------------------------
user = 'Klaus'
app  = 'Photoshop'

print(f'Once upon a time, there was a {app} User named {user}')
print(f'{user} wasted months on soul-draining tasks in {app}')
print(f'Until one day {user} said: Enough!')
print(f'And by accident he discovered that he could automate his {app} work with python')
print(f'But {user} knew nothing about python.')
print(f'And so, {user} has begun his programming journey.')
# 💪 Simple Excercise
#--------------------------------------------------
user = 'Klaus'
app  = 'Photoshop'

print(f'Once upon a time, there was a {app} User named {user}')
print(f'{user} wasted months on soul-draining tasks in {app}')
print(f'Until one day {user} said: Enough!')
print(f'And by accident he discovered that he could automate his {app} work with python')
print(f'But {user} knew nothing about python.')
print(f'And so, {user} has begun his programming journey.')
# 💪 Simple Excercise
#--------------------------------------------------
user = 'Klaus'
app  = 'Photoshop'

print(f'Once upon a time, there was a {app} User named {user}')
print(f'{user} wasted months on soul-draining tasks in {app}')
print(f'Until one day {user} said: Enough!')
print(f'And by accident he discovered that he could automate his {app} work with python')
print(f'But {user} knew nothing about python.')
print(f'And so, {user} has begun his programming journey.')

Summary

Well done! Now you know:

  • Basic DataTypes in Python (String, Integer, Float, Boolean, NoneType)

  • How to store data in Variables (name = 'Erik')

  • How to use String-Formatting (f'My name is {name}')


Alright and the lesson is over

How does that feel?

We're still warming up, as we need a few more concepts before we can start practicing with Python. So, buckle up 🚗💨!

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Go over the code snippets shown in this lesson and try it out yourself.

Bonus point if you actually going to write it yourself instead of blindly copy-pasting. When you copy-paste you learn very little.

However, if you going to write it yourself it will help you understand these basics better. You might also encounter error messages if you make a mistake, and that's okay. Programming journey is impossible without seeing error messages, you just need to make sure you follow python syntax rules.

⌨️ Happy Coding!

⌨️ Happy Coding!

⌨️ Happy Coding!

If you have any questions, leave them in the YouTube Comments.

If you have any questions, leave them in the YouTube Comments.

If you have any questions, leave them in the YouTube Comments.

Why you show old string-formatting method?

Why you show old string-formatting method?

Why you show old string-formatting method?

Have Your Own Question?

Have Your Own Question?

Have Your Own Question?

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

PS. Python can change your career and how you think about problems.
Be Careful 🙂

PS. Python can change your career and how you think about problems.
Be Careful 🙂

PS. Python can change your career and how you think about problems.
Be Careful 🙂

Sposored by LearnRevitAPI.com