Data Types (part 1) - Value Types | Vyper (0.2) - Sottotitoli bilingue

Let's learn about the different data types in Piper.
Each data type is either a value or a reference.
In this video, we'll go over value types, and in the next video, we'll go over references.
First of all, what are value types?
value types are data types that are passed by their values.
For example, let's say that we have an unsigned integer named x and it is equal to 1.
And then we reassign variable x to a variable named y.
And then we modify the variable y.
For example, we add one to its current value.
Now the big question is, what is the value of x?
And the answer is x is still equal to one.
This is because when we assign x to y, the value of x was copied over to a variable y.
So that when we change the value of variable y, it doesn't change the value of x.
So that's value types.
They copy variables by their variable y.
so that making a change to one variable does not affect the other variable.
Let's now take a look at value types available in Viper.
The first value type that I'm going to show you is a Boolean.
So I'll name it B and then we'll say it's a public variable and up type.
Boo.
By declaring this variable as public, we'll be able to access this variable after we deploy it using Remix.
I'll make a separate video about the different visibility of the variable.
For now let's just go over what this line of code is doing.
Here we're declaring our variable named called b.
The type of this variable is a boolean and it is a public variable which means that we'll be able to get the value of this b variable after the contract is deployed.
All moving on another value type is int 128.
So we will name it i and then it will be public and we can declare the type has int 128.
The range of this variable goes from negative 2 to the 127 to 2 to the 127.
So this is the data type that you will want to use when you want to handle both negative and positive numbers.
Next, we have Uint 256, which ranges from 0 to 256 minus 1.
and this is the variable to use when you're only dealing with non-negative numbers.
In Viper we also have decimals.
The range of decimals is same as in 128 and it supports up to 10 decimal places.
Now this is a useful data type that is not available in Solidity.
Alright, moving on, we have our address type.
Bites 32 and it's useful when you want to store the cryptographic cache of something.
Now surprisingly we also have byte arrays and strings as value types.
So this means that every time you copy a byte array or a string, it will copy each element in the array.
If you have a string of length 1000 and then reassign it to another variable.
Basically are running a for loop for 1000 characters copying each element.
Let's quickly go over what these two lines of code are doing.
For the first one, BS, we're declaring a variable named BS, and it's a public variable.
The data type is bytes, and this byte is at most 100.
Likewise, first chains were declaring a variable named s, it's a public variable,
of type string, and this variable can be at most 100 characters long.
These are the value types available in Viper.
Let's set these variables to some concrete value.
So we'll define init function.
And the first thing that we need to do is say, add external, and say def to underscores init to underscores parentheses calling.
Now this external means that this init function can be called from outside of the contract.
and then we'll set the variable b to true by saying self dot b equals true.
We'll set i to minus 1 by saying self dot i equals minus 1.
We'll set the unsigned variable to some positive number.
We want to We'll set the decimal to 3.14 and we'll set the address type to some random
address and then the bytes 32 to also some random bytes 32.
The byte array,
we also set it to some random byte,
and we'll say that it's a byte by prefixing with a b, double quotes, slash x, and then the value, 0, 1.
For the string, we'll say this is a string.
Let's make sure that this contract compiles.
So I'm going to open my terminal and type Viper, followed by the name of the contract here.
I named it value types.
And you can see that our contract compile is run through a demo using remix.
So I'm going to copy the code.
Open remix.
And then activate Viper.
Next, I'll create a Viper file.
Here, I'll name it value type.by paste the code.
And then click on the biker compiler and then click remote compiler and then click compile All right,
let's deploy this contract,
so I'm gonna click deploy scroll down and then click on the contract that was just deployed and let's check that
these variables are set to these values over here address b is for boolean b32 is bytes 32 bs is bytes array g is decimal.
Note that remix does not know how to handle decimal types yet.
Alright, moving on, let's check the value of int 128.
It's equal to minus one.
the string value, this is a string, and the on-site value is 1 to 3, right?
So are the value types of Viper, Boolean, on-site and signed integers, decimals, edges, bytes 32, and also strings and bytes array.
The last two data types being a value type is a little bit surprising, since in Solidity these two types are reference types.
Lingua di traduzione
Seleziona la lingua di traduzione

Sblocca altre funzionalità

Installa l'estensione Trancy per sbloccare altre funzionalità, tra cui sottotitoli AI, definizioni di parole AI, analisi grammaticale AI, parlato AI, ecc.

feature cover

Compatibile con le principali piattaforme video

Trancy non fornisce solo supporto per sottotitoli bilingue su piattaforme come YouTube, Netflix, Udemy, Disney+, TED, edX, Kehan, Coursera, ma offre anche traduzione di parole/frasi AI, traduzione immersiva a tutto testo e altre funzionalità per pagine web regolari. È un vero assistente per l'apprendimento delle lingue tutto in uno.

Tutti i browser delle piattaforme

Trancy supporta tutti i browser delle piattaforme, inclusa l'estensione per il browser iOS Safari.

Modalità di visualizzazione multiple

Supporta modalità teatro, lettura, mista e altre modalità di visualizzazione per un'esperienza bilingue completa.

Modalità di pratica multiple

Supporta dettatura di frasi, valutazione orale, scelta multipla, dettatura e altre modalità di pratica.

Sommario video AI

Utilizza OpenAI per riassumere i video e comprendere rapidamente i contenuti chiave.

Sottotitoli AI

Genera sottotitoli AI precisi e veloci per YouTube in soli 3-5 minuti.

Definizioni di parole AI

Tocca le parole nei sottotitoli per cercarne le definizioni, con definizioni alimentate da AI.

Analisi grammaticale AI

Analizza la grammatica delle frasi per comprendere rapidamente il significato delle frasi e padroneggiare punti grammaticali difficili.

Altre funzionalità web

Oltre ai sottotitoli video bilingue, Trancy fornisce anche traduzione di parole e traduzione a tutto testo per pagine web.

Pronto per iniziare

Prova Trancy oggi e scopri le sue funzionalità uniche

Scarica