It is currently 27 Feb 2021, 12:16

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  🡆 Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Variables in Python

Simple lessons to get your started in Python language
tim
GL Blogger

Variables in Python

Post#1 by tim » 29 Sep 2018, 15:17


Variables are named items that can hold some data/information.
Variable names can be made out of underscores (_), letters or numbers, but they have to start with an underscore or a letter.
Some example of valid variable names are:
mystring
_mystring
mystring1

To initialize (set a variable to hold some information) a variable, you'd type the variable name then equal sign then the value/data you'd like the variable to have, for example:
my_name = "John"

It'll set the variable named on the left of the equal sign to hold whatever data you have on right of the equal sign.

For fun and practical purposes I'll show you how to concatenate (combine) strings in Python.

You can concatenate strings by using the plus (+) signs between 2 or more strings. For example, if you want to combine "John" and "Smith", you'd type:
"John" + "Smith"

Now, that you know how declare variables and concatenate strings, let's have some fun. We'll declare a variable named firstname, another one named lastname, and one last one named fullname that uses concatenation to combine the 2 previous variables (with a space character between them for neatness) like below:
firstname = "John"
lastname = "Smith"
fullname = firstname + " " + lastname

Now it's your turn to play around with what you've learned here (Click Run to run code).

Try playing around with different strings and different variable names.

Next lesson: Numbers in Python - Previous lesson: Strings in Python
aka Tin

         


GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  🡆 Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 1 guest