Python – A quick look at some of these Data Sets in IDLE Console, and taking a first look at the Splice Operator : !

DataTypes

I probably won’t use all here, but I will use as many as possible, to get demo’s for all these concepts out of the way – This is all thanks to one following Google Play App:

https://play.google.com/store/apps/details?id=com.vrpmeone.LearnPython&hl=en_US

If you are a beginner download this! I enjoy my “Automate the boring stuff for more expansive reading, but this is direct / concise / very direct explanations of how to use operators if you can find the logic in the examples on the screen.

Seriously, get that app to squeeze some studies over your lunch hour or before bed time, the explanation + examples make for perfect clear explanations very quick.

Some quick basics review, and data types in action using Pythin IDLE Console

One very basic but important note – Variable String cannot being with an Integer, must either start with a _ or letter (string) that can contain numbers, but cannot contain special characters or blank spaces:

varErr1

A variable also cannot have words similar to other pieces of the code, so make sure your identifier is not part of some list / dictionary / tuple / part of the code or program.

Though Variables that are good to go are as follows, the big thing is remembering the ” :

VarErr2

I was actually expecting that last one to eventually condense itself using the “Long Integer” String of like 1230023849238L (note Long Integers NEVER use lower case L’s to avoid confusion in the String – Yes really!), but what this IS used for is

There is another cool function that I didn’t realize existed called “type” just in case you were wondering what KIND of Data Set is in your variable(!) :

VarErr3

You can also accomplish this with print (type(a)) but I found it could just be done a “type” as a function rather than mixing in print function as well.

Moving along to Strings is pretty straight forward

VarErr4

Syntax is a little off but always where it doesn’t matter 🙂

What as see here^ is “Concatenation” or the combining of Two Strings to create a single output value that we expected (only a bit misspelled).

Its a really easy term that just sounds confusing to me and could become confusing when you have more than two Strings, but this is Concatenation at its simplest here.

Playing with the “List” Data Types in different ways and using a “:” Splice Operator

As shown in the top graphic these are a list of Objects which are considered “Mutable” which I unfortunately have no idea what that means yet, but I will get back to Mutable vs Immutable in my future Python studies!

This is something I’ve learned from a Python App on my phone, which I wanted to play with on my own IDLE Console here, so lets start first with a basic list:

VarErr5

Here we can see whether we print a list or just type l, it will output the same list, however once we get into using our splice operator we can pick and choose what parts of the list we want to display:

VarErr6

This is very new to me, so I am sure this is not the last we will see of splicing, but when it comes to either Lists as a Data Type or Strings themselves, it just tells the program what parts of it that it wants to list, in this case 0 = the first List Value, and 4 = Final List Value.

Whereas with Strings themselves it gets a bit odd as can be seen here when using the Splice Operator:

VarErr7

So using the Splice Operator of : is admittedly a bit of a mystery to me here (and I’m sure I will revisit it more informed in the future), however we can see that it does start at 0 as a # in the value.

I had a curiosity killed the cat moment at there when I did print (str1[0]) and 7

It is odd to me that Splicing 0:7 was StringN which I first thought that N was #7 value in that string, however when I did 7-15 it started at the ‘unmberOne’, meaning that N’s value in this string is 6 however it was the ending value in 0:7 – So I have some review to do with Splicing Operator and will need to get back to this.

PLEASE – Comment if you know what the deal is with this discrepancy!

I have not seen the Splice Operator before tonight, and I am bit tired, so I am not sure if I am just missing an obvious concept there as it was more straight forward with lists but with Splicing the hairs of a String I am a bit lost there right now.

Moving on!

Tuples – Basically the same as a “List” only it is considered Immutable

The best “easiest” explanation of immutable I have found in regards to Tuples is that it is a read-only data set that cannot be changed, making it immutable, as it cannot be changed though I am not far enough in my studies to fully understand why that matters.

Though they work ultimately the same as a List as far as my studies have gone:

VarErr8

Again the Splice Operator here escapes me, as the 0:1 does ‘Hello’, so its showing the String and outer comma (outside of the string) while 0 only shows ‘Hello’, however 0:3 does not show ‘Hello’, ‘World’, but also adds the 5 which I’d expect from 0:4

So that is just completely confusing to me, I’ll be doing an article specifically on the topic now of Splice Operators, that topic has officially earned my study scorn!

Last but not least we have the Dictionary Data Type!

This won’t be conclusive but just a quick first look at the Dictionary Data Type, how to run some commands, and just a really high level view.

This is the same concept as the JSON Key:Value pair (I believe it was JSON), where you assign a “Value” to a “Key” almost like assigning a  value to a variable only in bulk!

Quick demonstration of this will just be #’s and names to demo this straight forward:

VarErr9

Much more straight forward, really just a bulk way of assigning variables it seems and to be able to call them out, as I haven’t played with trying to replace Dictionary words yet, however this worked pretty well so I will leave it at this working example 🙂

That is it for tonight and I believe for very beginner topics for Python

I am still taking baby steps, however I want to make sure I am all set for Kirk Byers “Python for Network Engineers” 8 week course on March 3rd that you should be signed up for if you are not already, by signing up here:

https://pynet.twb-tech.com/email-signup.html

That whole course is going to be a series of articles on this webpage, hopefully growing more knowledgeable by the week! I am outta here, until next time!

2 thoughts on “Python – A quick look at some of these Data Sets in IDLE Console, and taking a first look at the Splice Operator : !

  1. Hi,
    Consider, I = [‘A0′,’A1′,’A2′,’A3’] # Index – 0=A0, 1=A1, 2=A2, 3=A3
    When you are fetching print(I[0:2])# You are seeking the values assigned to index range from 0 to 1 (omitting index-2)
    Same, print (I[2:4]) # It will omit last index always and only print the values assigned to the index from 2 to 3
    Summary, to print range – 1 : 3 (I mean, print (I[1:3]))
    python will consider, print ([1]), print ([2]).

    Pls consider the script and result –
    I = [‘A0′,’A1′,’A2′,’A3’]
    print (I[0:2])
    print (I[2:4])
    print (I[1:3])
    print (I[2:5])

    Result –
    [‘A0’, ‘A1’]
    [‘A2’, ‘A3’]
    [‘A1’, ‘A2’]
    [‘A2’, ‘A3’] # We do not have index range values assigned after 3.

    Like

    1. Hey thank you for the comment, I was OOO and never got to approve til now, I will review the context when I get a chance here. Much appreciated!

      Like

Leave a comment