Jump to content

Recommended Posts

Posted

Este es un tip que muchos lenguajes de programacion lo tienen como php y c++ pero casi nadie sabe que existe, espero traer mas aportes como este otroo dia

 

El operador ternario es una manera diferente de usar el if else. Se expresa de la siguiente manera

 

(Condicion)?"mostrar si verdadero":"mostrar si falso";

 

Donde en condicion ingresas la condicion booleana

 

En mostrar si verdadero puedes ingresar tanto variables,textos o combinar variables con texto

 

De la misma manera en mostrar si falso

 

Ejemplos serian

 

$Login= (users::user_exist($user)==true && users::user_pass($user, $pass))?"logeo con existo":"datos erroneos";

 

O

 

Return ($edad>=18)?true:false;

 

Que es mas practico que usar

If($edad>=18){

Return true;

}

Else{

Return false;

}

 

Es algo simple, pero de algo les a de servir

Posted

dejo ejemplos en lua y python:

 

bVar = True

print "true condition sentence" if bVar else "false condition sentence"

> "true condition sentence"

 

bVar = false

print(bVar and "true condition sentence" or "false condition sentence")

> "false condition sentence"

 

nota: en python también se puede utilizar el and/or.

Posted

dejo ejemplos en lua y python:

 

bVar = True

print "true condition sentence" if bVar else "false condition sentence"

> "true condition sentence"

 

bVar = false

print(bVar and "true condition sentence" or "false condition sentence")

> "false condition sentence"

 

nota: en python también se puede utilizar el and/or.

 

nota2: en python se puede usar de esa forma en versiones >= 2.5.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

This site uses cookies to enhance your browsing experience and provide relevant content. By continuing to browse, you agree to our We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. and Terms of Use. For more information on how we protect your data, please check our Privacy Policy.